Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

chbfiv

var++ causes var to = 0 after...

This topic is 5481 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

I have two int''s int qn=0; //Question number int ln=0; //Lesson number I have a loop that basicly works like this for(NumberofQuestions+NumberofAnswers) { if(qn == Lesson[ln].NumberofQuestionsforThisLesson) { //Skip to next lesson''s questions qn = 0; //reset Question number ln++; //increase Lesson number } printQuestionwithLessonID(qn,ln); qn++; } Whats so odd is when qn=100 in the loop(if ever) ln does something odd, it changes to 0 in a odd part of the loop. I never set, ln=0, in a funtion or anything, and the place ln becomes = 0 is when I call a sprintf() that has nothing todo with ln, but after that sprintf ln = 0. I consider myself a novice c programmer, but from what I can tell something is sharing memory with that ln and it might be because of a char overflow somewhere. Though I don''t see it yet, does anyone else have an idea as to why something like this would happen? I don''t mind posting my Code. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Hello chbfiv,

if after your sprinf call ln is being set to zero then I bet the sprintf is over writing the memory location ln is using.
Is your sprintf write to a var that is declear before ln.
ex
char temp[8];
char ln;

...

sprintf(temp, "%s", something);
Were something is a string like this char something = "12345678"
then the null is copied into ln which would set ln to zero.

Without seeing how you decleared the vars and what the sprintf is doing can''t gave anymore help.

Lord Bart

Share this post


Link to post
Share on other sites
Yeah you got it, I was on the right track, but I just took a snapshot of the memory footprintf of the var used in the sprintf, though they were nowhere near each other in the code when the var(char[2]) used in sprintf when from 99 to 100, that last 0 copyed over "ln". I thank you for the tip to reboot my debugging=)

[edited by - chbfiv on September 22, 2003 5:49:36 PM]

Share this post


Link to post
Share on other sites

  • 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!