The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Run a c program
Discuss Run a c program in the C Programming forum on Dev Shed. Run a c program C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 10th, 2012, 07:59 AM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 4
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
|

November 10th, 2012, 08:11 AM
|
|
|
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.
|

November 10th, 2012, 08:18 AM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 4
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?
|

November 10th, 2012, 08:29 AM
|
|
|
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)
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|