Sign in to follow this  
Craig M

Why does this throw an access violation segmentation fault ?

Recommended Posts

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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this