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
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
"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
> 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.
Hi. Thanks. That's good to know. I would sure like to know exactly how to do this:
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, SteveYou can set the command line parameters up so that your main() sees a correct argc and argv.
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 06:25 AM.
Monday - what a way to spend a seventh of your life
If you really want to try a command line debugger, gdb is included with Dev-C++ and ntsd is the windows debugger. Good luck.
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]
Try this with various things typed into your Debug->Parameters dialogCode:#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { if ( argc > 1 ) printf( "%s\n", argv[1]); system("PAUSE"); return 0; }
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