Thread: Bad output -- possible input buffer problems

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I didn't use a debugger. For projects like this, you don't actually need one. While they can be extremely helpful, I wouldn't get completely dependent upon it.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by MacGyver View Post
    I didn't use a debugger. For projects like this, you don't actually need one. While they can be extremely helpful, I wouldn't get completely dependent upon it.
    Oh, sure, I didn't either [even if I took a bit longer than you to post my answer] - I just followed the logic of the code, and realized that there was no resetting of the gDigits variable - then I checked the for-loop and saw that it ends at -1.

    And of course, even if you do need to follow what happens in the code, a simple way that often works better than the debugger, is to add "printlines", e.g lines that do printf() to show the intermediate results of some operation, e.g. print the "number of digits found" at the end of convertNumber() - and when it comes up with 3 the second time, you should start worrying. Depending on your ability to guess, the number of steps necessary to get it to go wrong, it may be faster to get a printline to the right place than it is to step through the code until you spot the error. I often use both - together or separately. But I wouldn't want to be without the debugger.

    Oh, and one final point: calling a variable "stop", then setting it to 1, and doing "while (stop == 1)" is contrary to my logical sense. You should either call the variable "more" and use it like you do stop now, or keep the name stop, but use it with an initial value of 0 and then stop when the value is 1.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Send output to keyboard buffer
    By DReynolds in forum C Programming
    Replies: 2
    Last Post: 06-06-2007, 03:44 PM
  2. Having Buffer Problems With Overlapped I/O --
    By Sargera in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 04:46 PM
  3. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 11:28 PM
  4. text input buffer clearing
    By red_Marvin in forum C++ Programming
    Replies: 4
    Last Post: 03-20-2003, 03:17 PM
  5. Input problems with DJGPP?
    By Hardboy in forum C++ Programming
    Replies: 10
    Last Post: 03-13-2003, 07:29 PM