Solved

Problem about variables

Posted on 1998-09-10
4
184 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
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 writing to files in the C programming language.

763 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

10 Experts available now in Live!

Get 1:1 Help Now