# Why does this throw an access violation segmentation fault ?

## Recommended Posts

Craig M    108
Basically, whenever I compile with a single thing changed in these few lines of code, I get that in the debugger (Dev-C++): My map is defined like this: int mizzap [ROWS][COLS]; This one Works: infile = fopen(ifilename,"r"); for(c = 0; c < ROWS; c++) { fscanf(infile,"%d",mizzap [c]); } fclose(infile); This one doesn't: infile = fopen(ifilename,"r"); for(c = 0; c < ROWS; c++) { fscanf(infile,"%d",mizzap [r][c]); } fclose(infile); Thanks in advance for the help!

##### Share on other sites
SiCrane    11839
When you pass arguments to fscanf(), you're supposed to use the address of the variable, not the variable itself. This line:
fscanf(infile,"%d",mizzap [r][c]);

should be:
fscanf(infile,"%d", &(mizzap[r][c]));

Though if you're using C++ I'd recommend using the stream IO instead.

##### Share on other sites
jfclavette    1058
How big is mizzap ? Is it even a 2D array ?
Where the hell does 'r' come from ?
Why is c compared to the number of rows ? I suppose you want r to represent the row and c the column ?

##### Share on other sites
Craig M    108
r indicates rows, and I'm sorry that I forgot to mention that Mizzap is indeed an array, personally, I like the name :D.

And also, big thanks SiCrane, I dont know how I overlooked that too. And I am using C, just for reference.