Solved

Problem about variables

Posted on 1998-09-10
4
185 Views
Last Modified: 2012-05-04
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?
0
Comment
Question by:SHAHZAD
4 Comments
 
LVL 16

Expert Comment

by:imladris
ID: 1252617
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.

0
 
LVL 2

Expert Comment

by:duneram
ID: 1252618
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
0
 
LVL 3

Accepted Solution

by:
elfie earned 20 total points
ID: 1252619
If you can debug your program, use a debugger to pinpoint the line of code which has the 'side effect'.

If you don't have a debugger, use the simple way of inserting printf lines in your code, and by a number of recompile/reruns
and always narrowing the piece of code between the printf your can also find the 'side-effect' line. (printf the variable that changing).

Then examing the variable modified in this piece of code, and look for things like 'dunaram' explained.
0
 

Author Comment

by:SHAHZAD
ID: 1252620
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.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now