C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 10th, 2012, 07:59 AM
McDuck4 McDuck4 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 4 McDuck4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 35 sec
Reputation Power: 0
Run a c program

Alright first of all, i just spend 30 min making a threat, where i have put screenshots in, so it might would help me to understand, and explain what my problem was. But the site dosent allow me to????? I really dont understand why, especially when some people are newbies, this would be the perfect place for that.

Hello everybody.

I really hope someone can help me.

I just startet on a course, where we have to learn C programming. I downloaded Xocde and followed this installation the installation proces.

I also installede the GRR commandoline toll, and it looks like it is working

I tried to make a hello world, from the page "thenewboston.org", which is running fine from within the Xcode program, but i want to run the program from my terminal on my mac, but i dont know what to write.
my file is called "main.c". Then i go to my terminal and find the folder where my file is, then i write:

g++ main.c (and then it just goes to the next line. Then i write): /.main.c and then i get an answer where it says: "Permission denied"

But what am i doing wrong? I am out of options now, so i hope someone can help me?

Best Regards
Mads

Reply With Quote
  #2  
Old November 10th, 2012, 08:11 AM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
The compiler generates an executable file with a different name than the file with the source code.
Probably your compiler generated an executable file named "a.out". Try

Code:
$ g++ main.c
$ ./a.out
<OUTPUT OF YOUR PROGRAM>
$


You can make the compiler output a specific name instead of "a.out". For instance "executable"

Code:
$ g++ main.c -o executable
$ ./executable
<OUTPUT OF YOUR PROGRAM>
$


Also you really, really should enable warnings and mind them, eg

Code:
$ g++ -Wall main.c -o executable
<SOME WARNINGS>
<EDIT CODE TO ADDRESS THE WARNINGS>
$ g++ -Wall main.c -o executable
<NO WARNINGS>
$ ./executable
<OUTPUT OF YOUR PROGRAM>
$

Last edited by bdb : November 10th, 2012 at 08:15 AM.

Reply With Quote
  #3  
Old November 10th, 2012, 08:18 AM
McDuck4 McDuck4 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 4 McDuck4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 35 sec
Reputation Power: 0
perfect, thank you so much for that :-) it works now. The only thing that is annoying is, that when i get printed "Hello World", it is as the same line that my name of the comuter is. So I write:

Mads-Macbook-pro:test Mads$ get++ main.c -o main
Mads-Macbook-pro:test Mads$./main

and the output is:

Hello WorldMads-Macbook-pro:test Mads$

where i would like it said

Mads-Macbook-pro:test Mads$
Hello World

But i cant do anything about that?

Reply With Quote
  #4  
Old November 10th, 2012, 08:29 AM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
Quote:
Originally Posted by McDuck4
... it is as the same line ...


Print a full line within your program

Code:
puts("Hello World"); // puts automatically adds a newline

or
Code:
printf("Hello World\n"); // add newline manually (the \n)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Run a c program

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap