Honestly I dont
Which is why Im asking. Oh and I corrected the "/n" and switched it to "\". But yeah when I remove the entire else statement it works fine. I dont get it
Honestly I dont
Which is why Im asking. Oh and I corrected the "/n" and switched it to "\". But yeah when I remove the entire else statement it works fine. I dont get it
That's because your brackets makes the compiler think it belongs to the FOR loop. That's why we use identation. See, it's very easy to see now that I intended it properly.
Thats interesting. I never honestly thought indentations had such a big impact on how the compiler looks at things. Ill go ahead and make the necessary adjustments so they match what u did, and see what happens.
But the reason why I never thought about is is because I have worked with Java and Scheme, and never really had a problem with indentations...
The compiler doesn't care about indentation - but YOU do. It makes it so much easier to read. You've basically put the else-statement in the wrong place, and it's very easy to see with proper indenting.
Alright well, lets see what happens...
Ok I see it!
This is one reason that Python is a very good language to start learning in - indentation is part of the "syntax" there, so if you write:
then print x is part of the if-statement, print y isn't, purely based on indentation. So to get the correct behaviour, you HAVE to indent correctly.Code:... if (x > y) print x print y
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I honestly don't see it...
and I asked a friend of mine who has some experience with C and he doesnt see it either...
I moved the else statement, but it gives me the same parse error.Code:#include <stdio.h> int main(int argc, char *argv[]) { FILE *fp; char arr[200]; int filename; int numLines; const int MAX_LINES = 1; for (filename=1;filename<argc;filename++) { fp=fopen(argv[filename], "r"); if (fp !=NULL) { for(numLines=1;numLines<=MAX_LINES;numLines++) { fgets(arr,200,fp); fputs(arr,stdout); } } } else fprintf(stderr, "the file %s doesn't exist/n", argv[filename]); }
So I guess Im stuck again...
I have a feeling Ill end up kicking myself cuz its something simple
Oh alright...sorry guess I missed that. Well I guess I learned a thing or two about this. As long as it makes me a better programmer I guess. Thanks alot guys.