-
C not C++
I am learning C and when I tried to run a script from a tutorial, iut cant funt the header...
this is hte code:
Code:
#include < stdio.h>
void main()
{
printf("\nHello World\n");
}
and this is the error..
Code:
C:\>gcc c:\c\first.c
c:/c/first.c:1:20: stdio.h: No such file Or directory (ENOENT)
c:/c/first.c: In Function `main':
c:/c/first.c:4: warning: return Type of `main' is Not `int'
-
Point 1: It's <stdio.h>, not < stdio.h>. Remove the space.
Point 2: It's int main(void) in C, unless you're using arguments. The associated return 0; for a non-error condition is then also required.
-
Code:
C:\>gcc c:\c\first.c
c:/c/first.c: In Function `main':
c:/c/first.c:6: warning: `return' with a value, In Function returning void
c:/c/first.c:4: warning: return Type of `main' is Not `int'
c:/c/first.c:7:2: warning: no newline at End of file
Still errors:(
-
You didn't update your function signature. It's int main(void).
Also, text files are defined to end with a newline :)
-
Well, This tutorial sucks. Will you show me the hello world program?
-
Code:
#include <stdio.h>
int main(void) {
printf("Hello World!\n");
return 0;
}
That's what I'd always use.
-
Code:
C:\>gcc c:\c\first.c
c:/c/first.c:7:2: warning: no newline at End of file
-
-
I'm sorry, I don't know how. This ois my first actual day trying code.
-
When you hit "return" in your editor, you add a newline into the file. Text files are defined to end with a newline character for compatibility, and this is what GCC is complaining about.
-
Oh! I understand...Thanks..But shouldnt the DOS window display "Hello World?"
Code:
C:\>gcc c:\c\first.c
C:\>
It executes but nothing is printed to the screen.
-
That's because the program fully executes and the console window closes before you get a chance to see anything. You need to put some sort of pause after displaying any information, such as :
getch();
-
No, you only compile the program, not execute it.
Code:
C:\>gcc c:\c\first.c
C:\>\c\first.exe
Hello, World!
C:\>