Login Register


How to run your program. filter_list
Author
Message
How to run your program. #1
Ok so currently I am reading C Programming : Absolute Beginner's Guide, and am trying to follow along by writing and running the code.

Anyways, I downloaded Cod::Blocks IDE and went to File > New > Empty File, and then wrote a simple 'Hello world' program and proceeded to build and run it. According to the book, the program should have popped up in a terminal but nothing happened, can someone help me please?

Thank you.

P.S. I wrote the code properly, I quadrouple checked the thing, I used #include <stdio.h>, main(), printf(), return 0, and put all the semicolins.


RE: How to run your program. #2
Hard to tell you whats wrong when all youve done is say it doesnt work and you promise the code is correct.

Operating System, the Code, IDE version, and any errors or error logs that might be generated are all pretty important to debug problems.


RE: How to run your program. #3
OS: Linux Mint 17

Code:
#include <stdio>

main()
{
printf("Hello world./n");
return 0;
}

Code::Blocks Version: 13.2

Code::Blocks Build Log:

Checking for existance: /home/myname/Documents/Untitled1
Execting: xterm -T '/home/myname/Documents/Untitled1' -e /usr/bin/cb_console_runner "/home/myname/Documents/Untitled1" (in /home/myname/Documents)
Process terminated with status 255 (0 minute(s), 3 second(s))

I do not believe the problem is that I did somthing wrong, but I didn't do somthing I needed in order to have the program pop up in a terminal when it runs.


RE: How to run your program. #4
Maybe xterm is missing.

Install xterm:

Quote:% sudo apt-get install xterm

And then try to compile your program.
[Image: MUJ8qSW.png]
-----------------------------------
Now learning:
Android Development, Java
Working on:
An FTP Client for Android
-----------------------------------


RE: How to run your program. #5
Have you considered compiling and running your code directly from the terminal? In my opinion, it could be good for a beginner because this lets you "touch" the compiler.

(06-07-2014, 02:20 AM)MRIDGAF Wrote:
Code:
#include <stdio> main() { printf("Hello world./n"); return 0; }

Just a few notes: while "main()" is enough, the compiler should warn you about missing return type (and parameter), hance you should prefere "int main(void)"; in the "printf" you used "/n", while you probably meant "\n", with backslash (escape sequence).


RE: How to run your program. #6
(06-07-2014, 09:07 AM)erpicci Wrote: Have you considered compiling and running your code directly from the terminal? In my opinion, it could be good for a beginner because this lets you "touch" the compiler.

(06-07-2014, 02:20 AM)MRIDGAF Wrote:
Code:
#include <stdio> main() { printf("Hello world./n"); return 0; }

Just a few notes: while "main()" is enough, the compiler should warn you about missing return type (and parameter), hance you should prefere "int main(void)"; in the "printf" you used "/n", while you probably meant "\n", with backslash (escape sequence).

It's best to be explicit, yes. If the compiler gives you a warning, that's more often than not an indication that you're doing something bad.

And:
Code:
#include <stdio>

Should be...
Code:
#include <stdio.h>

If nobody else within this thread caught that from a hello world example in C, then none of the above members should be trying to help others in C programming related threads IMHO...

@OP: next time if you're having issues with code, don't assume that you've written things properly as you clearly didn't... Your original post states that you included <stdio.h>, yet I see <stdio> which is wrong... If you get a compiler error, you DIDN'T write everything properly.

Here is the proper code:
Code:
#include <stdio.h> int main() { printf( "Hello world.\n" ); return 0; }
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]








Users browsing this thread: 1 Guest(s)