Code:#include<stdio.h> void main() { int x=0; int y=0; char c; FILE* HUG; FILE*fopen(); HUG=fopen("c:\\beat.bmp","rb"); char array[600][480]; c=getc(HUG); while(c!=EOF) { array[x][y]=c; y++; c=getc(HUG); if(y==480) { x++; y=0; } } fclose(HUG); }
Code:#include<stdio.h> void main() { int x=0; int y=0; char c; FILE* HUG; FILE*fopen(); HUG=fopen("c:\\beat.bmp","rb"); char array[600][480]; c=getc(HUG); while(c!=EOF) { array[x][y]=c; y++; c=getc(HUG); if(y==480) { x++; y=0; } } fclose(HUG); }
I keep getting these errors no matter what I do...
error C2143: syntax error : missing ';' before 'type'
error C2065: 'array' : undeclared identifier
error C2109: subscript requires array or pointer type
Last edited by noethe; 06-12-2013 at 04:48 PM.
Your indentation is awful. Please post more readable code next time. Read this: http://sourceforge.net/apps/mediawik...le=Indentation
Line numbers with those errors would really help. When I compile the code you posted, I get the following errors:
Are you sure the code you posted is identical to the code that produced those errors? If made changes and didn't save them, the compiler could be using an old version of code.Code:gcc -Wall -Werror -ggdb3 -std=c99 -o bar bar.c bar.c:4:6: error: return type of ‘main’ is not ‘int’ [-Werror=main] bar.c: In function ‘main’: bar.c:13:8: error: variable ‘array’ set but not used [-Werror=unused-but-set-variable]
Anyway, I don't see anything in there that would cause the errors you posted. As for the errors I got:
line 4: It's int main, not void main, and make sure you return a value at the end, 0 is the convention for success. Read this: FAQ > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[]) - Cprogramming.com
line 13: You assign values to array, but never do anything with the values. I assume that's because this code is not complete.
Also, the following line is not necessary since the prototype for fopen is in stdio.h. Remove it.
Code:FILE*fopen();
You also need to make sure you don't overrun your array. What happens when x reaches 600?
bit∙hub [bit-huhb] n. A source and destination for information.
Thanks for the reply.
Yeah, the code is incomplete because this was my first step. But yes I keep getting these same errors no matter what and I'm going crazy. Could it be my compiler ?? I don't know I've stripped the code down to just this section and even started a new project so the compiler would only use that code but still...this
c(13): error C2143: syntax error : missing ';' before 'type'
c(20): error C2065: 'array' : undeclared identifier
c(20): error C2109: subscript requires array or pointer type
Good catch by bithub, you should check to ensure x doesn't exceed 600. Note, instead of using a literal 600, define constants
Then, if you want to change your code to work with different size images, it's only two small changes in one place, instead of dozens in several places.Code:#define MAX_X 600 #define MAX_Y 480
It could be your compiler, but not in the "it's a bug" sense, rather the "you're compiling with the wrong settings" sense. What compiler are you using? It doesn't look like GCC, so I can't be of much help.
Did you fix the declaration of main like I suggested, add a return value and remove the unnecessary line? If not, do so. It probably wont fix the problem, but it ought to be done anyway. Also, try moving the definition of array up with the other variables. It's possible your compiler doesn't like mixed statements and declarations.
Lastly, you need to check the return value of fopen to make sure it's not NULL before you proceed. No point in trying to read from a file you can't open. Add this immediately after the fopen call:
Code:if (HUG == NULL) { perror("fopen"); return EXIT_FAILURE; }
You might be using a very strict C89 compiler. What happens if you move the declaration of array above the call to fopen()?
Also, you need to declare c as an int to properly compare it to EOF.
bit∙hub [bit-huhb] n. A source and destination for information.
As bithub mentioned, in C, you need to declare all variables at the start of a function. In this case, the error is caused by the fact that you declared char array[][] after the call to fopen. Move that line up to where you declare the other variable and the error(s) should go away.
O_o
The error format is what "Microsoft Visual C++" uses which is not a C99 compiler.
As far as I know, "Microsoft Visual C++", as a C compiler, doesn't even have the option of "mixed declaration".
Soma
Yes, I changed void main to int main, removed the extra line, added a return value,changed c to type int instead of char, and added the code you suggested. I'm using Microsoft studio express 2010.
You guys rock! I moved the declaration to the top of the program and those errors just disappeared! I've been just going crazy trying to figure this out and you guys really helped( wipes tear from eye) .