Completely New at Programming

dark_legacy2006

New Member
alright so heres the deal im interested in learning to program
-ive chosen my compiler
-ive found some tutorials (very basic)

and im sure everyone knw the most commmon program is "Hello World"

the compiler porgram i am using is Dev-C++ and this is what it looks like (same as tutorials)

#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}

few questions
1 how do i run this program, ive compiled it and when i go to run it a black box pops up and closes
2. IS the very first line neccessary

help appreciated this is somthing i am interested in
thanks in advance
 
I see you're learning C, my favorite language by far :D. Although C may be extremely difficult to learn if you are new to programming, once you have the basic concepts mastered you'll be good to go since C is not a very "big" language. The easiest way to make this program behave the way you want it to (on a Windows platform) would be to add the getchar() function right before the return statement in main. So it would look something like this:

Code:
#include <stdio.h> /* "includes" the standard library */
int main(void)
{
    printf("Hello World\n");
    getchar(); /* waits for the user to press the enter key */
    return 0; /* exits the program */
}
The first line of code:
Code:
#include <stdio.h>
is necessary if you wish to have access to all the functions of the standard library. "printf" is an example of a function from the standard library. Not all of the functions in the standard library are immediately added to the program with this line of code. Only functions that are explicitly called for in the program will be included in the final executable.

I recommend that you pick up a copy of The Second Edition of The C Programming Language (ANSI C) by Brian W. Kernighan and Dennis M. Ritchie. Ritchie was the original developer of C and this book is basically the bible for the language. It's geared more toward existing programmers, but still can be easily understood by a beginner. My first programming language was C so if I can do it, anyone can :).
 
Back
Top