A simple question on C
Hi folks,
FedoraCore 2 I just began to learn C and met following problem. Using 'emacs' to create a file on /home/user/hello.c with following content; Code:
#include < stdio.h> $ gcc /home/user/hello.c (Also tried as root #gcc /home/user/hello.c following warning popup; /home/user/hello.c:1:20: stdio.h:No such file or directory /home/user/hello.c: In function `main': /home/user/hello.c:4 Warning:return type of main' is not `int' # find / -name a.out Can't find the executable file 'a.out' # find/ -name stdio.h found many /stdio.h ..... Please advise what is the problem and how to rectify it. TIA B.R. satimis |
Code:
#include < stdio.h> That will fix you library problem. Second change void to int as void is c++ (I could be mistake correct me if I am wrong) Also add in return 0; at the end for good programming practice (As program will now be expecting a return type of int) |
I'm not a c person really...
i would try using 'int main()' and doing 'return 0;' as your last statement anyway I think that this is more ... uh ... standard I guess? but its good to return something |
dang you just beat me to that one, tim
|
Hi tim1235 and fenderman11111
Tks for your advice. Please provide more detail as I'm only a biginner. Tks. Quote:
Noted with thanks. Quote:
int main() instead of "void main()" Quote:
Tks. B.R. satimis |
Quote:
Your program should now look something like this: Code:
#include <stdio.h> |
I'm a Linux newbie and certainly not a pro at C, but looking through these boards took me back to my school days in C.
In C the function would look like this to declare a void return is expected: int main(void){ printf("\nHello World\n"); return 0; } One of my instructors actually deducted 1 point from a project because I used // instead of /* */ for comments because that's C++ and not C. What a guy. |
// is standard for C as of the C99 standard.
|
Hi folks,
Tks for your advice. Both advice of tim1235 and kingtas work with similar result. One thing I can't resolve. I must provide full path to call 'a.out' 1) [root@localhost user]# /home/user/a.out Hello World 2) [root@localhost user]# a.out -bash: a.out: command not found Can't work. Furthermore kindly to help me understand # gcc sine.c -lm What are the options '-lm' for??? Besides I follow following 2 documents found on Internet to learn C Language C Programming C Language Tutorial http://www.strath.ac.uk/IT/Docs/Ccourse/ (Remark: I'm using FC2 box to learn C Language. Although I have another FreeBSD box but it runs on a slower machine) Can you folks please recommend other documents available on Internet? TIA. B.R. satimis |
lol, it doesnt make much sense?
i just started learning c as well... i compiled the hello world program and it compiled without errors, but when i ran helloworld(chosen output file) it said bash not found. now when i read this post, i noted the whole directory... even when i was in same directory /home/can/source/ it wouldnt run. but when i typed in the whole directory w/ helloworld it ran? that doesnt make much sense.? |
Quote:
I got the querry as yours. I must run 'a.out' with its full path even already in its directory/folder B.R. satimis |
you can pick the file you want to compile too...
simply use gcc helloworld.c -o hello then run the /home/blah/blah/hello no more a.out |
Hi kahn,
Noted with tks satimis |
does anybody know what (no newline at end of file) means?
a lot of my programs give me this warning, but they still compile anyway? |
Hi kahn,
I found answer to following question; Quote:
./hello then it works B.R. satimis |
All times are GMT -5. The time now is 09:04 AM. |