Jump to content
  • Advertisement
Sign in to follow this  
Craig M

Why does this throw an access violation segmentation fault ?

This topic is 4706 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!