SHAHZAD
asked on
Problem about variables
I have written a program in TurboC 3.0.I am facing a serious problem.One of the variables automatically changes
during the execution of the program,which is not desirable.Can anybody tell me the solution?
during the execution of the program,which is not desirable.Can anybody tell me the solution?
Such an occurrence is almost always (99.9% of the time) caused by a logic problem in your code. To persue it here you should pinpoint exactly where/when the variable changes unexpectedly (which might by itself clarify the problem) and then post the code with an explanation.
it could also be a problem of limits:
here is an example:
char buf[3]={{0}};;
short x = 0;
char buf2[20] = {{0}};
strcpy(buf,"Hello World");
at this point buf has been overwritten. 'x' will more than likely (depends on the compiler) contain the 'l' from Hello instead of being 0. buf2 will have the rest of the string.
post the code
here is an example:
char buf[3]={{0}};;
short x = 0;
char buf2[20] = {{0}};
strcpy(buf,"Hello World");
at this point buf has been overwritten. 'x' will more than likely (depends on the compiler) contain the 'l' from Hello instead of being 0. buf2 will have the rest of the string.
post the code
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your answer elfie.
I have pinpointed the instant when the variable changes using
the debugger.Now tell me how to stop that variable from changing.
That variable actually occurs in a loop.
I have pinpointed the instant when the variable changes using
the debugger.Now tell me how to stop that variable from changing.
That variable actually occurs in a loop.