Reprint: http://blog.sina.com.cn/s/blog_4b6f784001011yvh.html
Example: #include <stdio.h>int main (int argc,char *argv[])
{
int i = ARGC;
printf ("argc:%d\n", I);
for (i = 0;i < argc;i++)
printf ("argv[%d]:%s\n", I,argv[i]);
return 1;
} output: [[email protected] (none) ~]# gcc-g-o main main.c
[[Email protected] (none) ~]#./main a b C
Argc:4
Argv[0]:./main
Argv[1]:a
Argv[2]:b
ARGV[3]:C debug: [[Email protected] (none) ~]# GDB Main
GNU gdb Red Hat Linux (6.6-8.FC7RH)
Copyright (C) 2006 free Software Foundation, Inc.
GDB is free software, covered by the GNU general public License, and you are
Welcome to change it and/or distribute copies of it under certain.
Type "Show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "Show warranty" for details.
This GDB is configured as "I386-redhat-linux-gnu" ...
Using host libthread_db Library "/lib/libthread_db.so.1".
(GDB) set args a B C
(GDB) R
Starting program:/root/main a b C
Argc:4
Argv[0]:/root/main
Argv[1]:a
Argv[2]:b
Argv[3]:cprogram exited with code 01.
(GDB)or you can do it with R a b C.