Chinaunix首页 | 论坛 | 博客
  • 博客访问: 651711
  • 博文数量: 128
  • 博客积分: 4385
  • 博客等级: 上校
  • 技术积分: 1546
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-22 14:05
文章分类

全部博文(128)

文章存档

2012年(2)

2011年(51)

2010年(75)

分类: C/C++

2010-09-06 18:06:06

例子:
#include
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;
}
输出:
[root@(none) ~]# gcc -g -o main main.c
[root@(none) ~]# ./main a b c
argc:4
argv[0]:./main
argv[1]:a
argv[2]:b
argv[3]:c
调试:
[root@(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 conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was 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]:c
Program exited with code 01.
(gdb)
 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/dashuliu/archive/2009/07/20/4363450.aspx
阅读(4740) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~