Debugging Cmd line

This is a discussion on Debugging Cmd line within the Tech Board forums, part of the Community Boards category; Hi. I have been writing programs that run from the command line. Is there a way to easily debug them, ...

  1. #1
    diligentStudent()
    Join Date
    Apr 2002
    Posts
    79

    Debugging Cmd line

    Hi. I have been writing programs that run from the command line. Is there a way to easily debug them, or do I have to debug via the IDE exclusively? Oh yes, I am talking Dev-C++ here. Thanks, Steve

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    "Have to?" If you've ever used a command line debugger, you'll see that it's a blessing that you can debug them from the IDE.

    Or am I getting something wrong?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > Is there a way to easily debug them
    Sure, just use the debugger like you would for any other program.
    You can set the command line parameters up so that your main() sees a correct argc and argv.

    After that, you just set breakpoints etc and do what you would normally do.

  4. #4
    diligentStudent()
    Join Date
    Apr 2002
    Posts
    79
    Hi. Thanks. That's good to know. I would sure like to know exactly how to do this:
    You can set the command line parameters up so that your main() sees a correct argc and argv.
    I am a newbie. I can PM the code to you if it would help. Just let me know if you think it would, and if it's OK to do so. All the best, Steve

  5. #5
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    argc and argv are the values that main uses when you start your program, thats why you see main as
    int main (int argc, char **argv[])

    the int argc is a counter of entities on the command line - the name of your program is one
    so if your program is called myProgram typing myProgram into the cli would set argc to one. If you typed myProgram -a then argc would be 2 and so one.

    argv is a pointer, a simple way of thinking of argv is an array of arrays,
    using the example above argv[0] is myProgram argv[1] is -a

    hopefully this should help you understand argv and argc a little better, if not i can post a simple c file to demonstrate it.
    Last edited by iain; 11-26-2004 at 05:25 AM.
    Monday - what a way to spend a seventh of your life

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If you really want to try a command line debugger, gdb is included with Dev-C++ and ntsd is the windows debugger. Good luck.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    In dev-c++, you do
    "Debug->Parameters"

    If at the command line, you would type in
    myprog.exe hello world

    In this dialog, you enter
    hello world

    > I can PM the code to you if it would help
    You can attach it to your post - or just paste the source code within [code][/code]

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
      if ( argc > 1 ) printf( "%s\n", argv[1]);
      system("PAUSE");	
      return 0;
    }
    Try this with various things typed into your Debug->Parameters dialog

  8. #8
    diligentStudent()
    Join Date
    Apr 2002
    Posts
    79

    Thumbs up That's Great!

    Hi Salem. I really appreciate it. I tried using 1 and 2 as parameters to the program I am attaching - it works great! I'm learning a great deal at the moment. I'm trying to complete the program (I've attached). Learning how to debug is on the top of my list. Best, Steve
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help in debugging this code
    By jaggesh in forum C Programming
    Replies: 4
    Last Post: 02-09-2008, 07:47 AM
  2. A simple question about GDB debugging
    By meili100 in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 01:05 PM
  3. Imposing Line Numbers automatically in the C code
    By cavestine in forum C Programming
    Replies: 14
    Last Post: 10-15-2007, 12:41 AM
  4. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  5. getting cmd line options
    By trekker in forum C Programming
    Replies: 2
    Last Post: 05-16-2003, 05:20 AM

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