![]() |
|
#1
|
|||
|
|||
Runtime Problem involving "printf" in C ProgramHi,Please be kind as it's my very first post.
OK, here's my problem. I have a (biggish) C program which compiles fine (using Borland C++ Version 5.01). Now when I run it, it crashes (floating point exception) at some point. I have identified the function in which it crashes but then when I try to view some intermediate variables in the function using a simple "printf" problem, then surprisingly, the program then runs through to completion wihout any problem. If I comment out the "printf" line, then it crashes again!! So it is very difficult for me to then debug in further detail by printing on screen any other variables as the "printfs" seem to cause the program to execute correctly, and removing them causes the problem. I haven't posted any of the code as I just want to know if anyone has encountered such a problem before and if they have any suggestions on what might be the cause. Thanks |
|||
|
#2
|
|||
|
|||
Re: Runtime Problem involving "printf" in C ProgramNope. Never saw that.
Quote:
Quote:
You need to read that very hard to miss post at the top of the forum. Especially Guideline 1.4 __________________
Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with. |
|
#3
|
|||
|
|||
Re: Runtime Problem involving "printf" in C ProgramQuote:
Yes, I have. The cause was a bug in my code (in at least one case it was the infamous "buffer overflow" caused by an out-of-range index for an array). Now, if you can reduce your "biggish" program to a smaller amount of code that exhibits the problem, post it. If there is no way to reduce your program to a smaller amount that still exhibits the problem, then I suggest one of the following: 1. (Top-down design) a. Organize your program so that you can start testing with a main program that calls various functions. For starters, just put some dummy stuff in the various functions. For functions that return values, make them return something that your main program can accept, and go on to the next step. b. Implement (write code) for the functions that you can test as you go. 2. (Bottom-up design) a. Define all of the functions that you need to use. Write a dummy main program for each that gives the function some realistic argument and tests the return value (and/or side-effects) of each function. b. After testing each function, put it into place in your "main" main program and go on to the next function. 3. (Top-down design, bottom-up implementation) Combination of the above In any case, before you start writing code, think about how you are going to test each stage of the development and think about how you are going to test the final product. Regards, Dave |
Recent GIDBlog
Running Linux Programs at Boot Time by gidnetwork
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| Type casts ? | kai85 | C++ Forum | 12 | 23-Jun-2005 12:04 |
| Problem with program | breggo | C++ Forum | 3 | 08-Jun-2005 13:51 |
| Having a small problem with this program | Krc784 | C++ Forum | 1 | 04-Nov-2004 22:25 |
| problem with the program under Borland | awmp-jansen | C Programming Language | 3 | 01-Jul-2004 17:05 |
Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The