cant find bugs

This is a discussion on cant find bugs within the C Programming forums, part of the General Programming Boards category; just wondering if anyone can help with fixing the bugs in this prog... cant seem to fix them. Code: #include ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    51

    cant find bugs

    just wondering if anyone can help with fixing the bugs in this prog... cant seem to fix them.

    Code:
    #include <stdio.h>
    #include "put_row.h"
    
               
       int main (int argc, char* argv[]) {
               
          int start = 10;
          int stop = 0;
          int step = 1;
          int c;
       
          if (argc > 1) {
             start = atoi(argv[1]);
          }
          if (argc > 2) {
             stop = atoi(argv[2]);
          }
          if (argc > 3) {
             step = atoi(argv[3]);
          }
       
          for (c = start; c > stop; c -= step) {
             put_row(c, step, stop);
             putchar('\n');
          }
       
          return 0;
    Code:
    #include <stdio.h>
    #include "put_row.h"
    
               
       void put_row(int start, int stop, int step) {
               
          int c;
          for (c = start; c != stop; c--) {
             printf("%d ", c);
          }
       }
    Code:
       void put_row(int start, int stop, int step);

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    27
    I cant really understand what the problem is but
    one thing i can see is that you call put_row with wrong arguments
    Code:
            put_row(c, step, stop);
    shouldnt it be:

    Code:
           put_row(c, stop, step);
    ??
    "Can i really learn this? If i cant, why bother?"

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    51
    forgot to say what i want the prog to do...

    when you run the prog ie

    % ./count 5 2
    5 4 3
    4 3
    3


    it currently prints the 2.

    also its meant to step like this:

    % ./count 9 3 2
    9 7 5
    7 5
    5

    any ideas?

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Read RoD's suggestion.

    Also,
    >>for (c = start; c != stop; c--)
    should be
    >>for (c = start; c != stop; c -= step)
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    51
    yep it works. thanks heaps guys.

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    61
    You do know that you're including stdio.h twice, right?
    $ENV: FreeBSD, gcc, emacs

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. please help!...find and replace
    By amy589 in forum C++ Programming
    Replies: 26
    Last Post: 10-13-2006, 06:42 PM
  2. Can't find DirectX!!!
    By Queatrix in forum C++ Programming
    Replies: 2
    Last Post: 07-24-2006, 07:50 PM
  3. Replies: 3
    Last Post: 06-09-2006, 09:53 AM
  4. Q: Recursion to find all paths of a maze
    By reti in forum C Programming
    Replies: 7
    Last Post: 11-26-2002, 08:28 AM
  5. RE: Find out running processes from command prompt
    By sampatel in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-18-2001, 07:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21