Solved

Problem about variables

Posted on 1998-09-10
4
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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 opening and reading files in the C programming language.

717 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