So, I have this C program, that computes the factorial of 5. I would like it to compile without error when using gcc -Wall. I have got it down to 2 cryptic ones, "main is usually a function," and "syntax error before { token in fac." Can anyone shed light on where to look for these errors and warnings either in the code, or on Google (tried Google), or GNU or something, without telling me exactly what is wrong? The code is thus:
#include <stdio.h>int n=5;int fac(int)int main(void){ printf("%d\n", fac(n)); return (0);}fac(int k){ if(k==0) return (1); else return (k*fac(k-1));}
9/12/2005 3:31:25 PM
in your function prototype of fac(), you are missing a semicolon at the end of the line, like this
int fac(int);
int fac(int k)
9/12/2005 3:36:15 PM
i haven't written anything in C in about 10 years now and i saw that right off
9/12/2005 3:39:36 PM
Yeah, its so obvious now. Thanks.
9/12/2005 3:39:55 PM
GCC's error messages are hard to figure out sometimes"main is usually a function" WTF is that supposed to mean? That error says nothing about the fact that the error is that you left off a semicolon from the function prototypeAs a rule of thumb, check the previous line of code from where you get your errors/warnings from. Many times, the lines that actually contain the error are right before the lines that the compiler sees as errors.
9/12/2005 3:50:45 PM
I dislike C/C++ for the kind of programming I do.Java for life.
9/12/2005 4:08:29 PM
gargs, thats completely irrelevant. You try to write code to interface directly with hardware, and you'll realize that you have to write code in C++ and interface to it through JNI in Java.For the work you do, i'm sure Java is a suitable language.
9/12/2005 4:22:55 PM
Man i remember when i didnt have to worry about using more than 64K of RAM for a program.*sign...those were the days
9/13/2005 3:33:43 PM
~Try removing 'void' from int main(void){...}~Also--WTF on declaring n as a global?~
9/13/2005 4:47:02 PM
dude, you didnt read any of the posts, marilynlov7 got the problems fixedand
int main(void)
9/13/2005 4:53:48 PM
Java sucks
9/13/2005 5:05:43 PM