|
-
Jan 17th, 2003, 12:47 PM
#1
Thread Starter
Hyperactive Member
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'
Kevin Carpenter
Currently Working in the CAOS (CA Operating System) Group
-
Jan 17th, 2003, 12:55 PM
#2
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 17th, 2003, 01:00 PM
#3
Thread Starter
Hyperactive Member
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
Kevin Carpenter
Currently Working in the CAOS (CA Operating System) Group
-
Jan 17th, 2003, 01:05 PM
#4
Monday Morning Lunatic
You didn't update your function signature. It's int main(void).
Also, text files are defined to end with a newline
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 17th, 2003, 01:15 PM
#5
Thread Starter
Hyperactive Member
Well, This tutorial sucks. Will you show me the hello world program?
Kevin Carpenter
Currently Working in the CAOS (CA Operating System) Group
-
Jan 17th, 2003, 01:18 PM
#6
Monday Morning Lunatic
Code:
#include <stdio.h>
int main(void) {
printf("Hello World!\n");
return 0;
}
That's what I'd always use.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 17th, 2003, 01:21 PM
#7
Thread Starter
Hyperactive Member
Code:
C:\>gcc c:\c\first.c
c:/c/first.c:7:2: warning: no newline at End of file
Kevin Carpenter
Currently Working in the CAOS (CA Operating System) Group
-
Jan 17th, 2003, 01:23 PM
#8
Monday Morning Lunatic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 17th, 2003, 01:25 PM
#9
Thread Starter
Hyperactive Member
I'm sorry, I don't know how. This ois my first actual day trying code.
Kevin Carpenter
Currently Working in the CAOS (CA Operating System) Group
-
Jan 17th, 2003, 01:28 PM
#10
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 17th, 2003, 01:32 PM
#11
Thread Starter
Hyperactive Member
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.
Kevin Carpenter
Currently Working in the CAOS (CA Operating System) Group
-
Jan 17th, 2003, 04:09 PM
#12
Hyperactive Member
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();
-
Jan 18th, 2003, 10:01 AM
#13
No, you only compile the program, not execute it.
Code:
C:\>gcc c:\c\first.c
C:\>\c\first.exe
Hello, World!
C:\>
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|