GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Oct-2005, 19:16
supamakia supamakia is offline
New Member
 
Join Date: Oct 2005
Posts: 1
supamakia is on a distinguished road

Runtime Problem involving "printf" in C Program


Hi,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  
Old 08-Oct-2005, 20:33
Guidelines Plz Guidelines Plz is offline
Junior Member
 
Join Date: Sep 2005
Posts: 87
Guidelines Plz is on a distinguished road

Re: Runtime Problem involving "printf" in C Program


Nope. Never saw that.

Quote:
Originally Posted by supamakia
So it is very difficult for me to then debug in further detail...
And totally impossible for us without some code.

Quote:
Originally Posted by supamakia
... if they have any suggestions on what might be the cause.
You're doing something wrong. What else is there to say with the info you've given?

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  
Old 09-Oct-2005, 10:09
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,147
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Runtime Problem involving "printf" in C Program


Quote:
Originally Posted by supamakia
Hi,Please be kind as it's my very first post.

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

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 GIDBlogRunning Linux Programs at Boot Time by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

All times are GMT -6. The time now is 05:52.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.