c c++ argc argv

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  /**********************
Name:a.out
Author:不学则死
Date:2012/9/20
CopyRight:转载注明出处
***********************/

/*
argc
是整个命令行参数的个数;
argv[0] 指向程序运行的全路径名;
argv[1] 指向执行程序名后的第一个字符串;
argv[2] 指向执行程序名后的第二个字符串;
...
argv[argc]NULL
*/
 
#include <stdio.h>
 
int main(int argc, char** argv)                    
{
    int i = 0;    
    printf("argc=%d\n",argc);
    for(i=0; i<=argc; i++)
    {
        printf("argv[%d]=%s\n", i, argv[i] );
    }
 
    return 0;
}



/*

root@ubuntu:~/eclipseworkspace# ./a.out
argc=1
argv[0]=./a.out
argv[1]=(null)
root@ubuntu:~/eclipseworkspace# ./a.out a
argc=2
argv[0]=./a.out
argv[1]=a
argv[2]=(null)
root@ubuntu:~/eclipseworkspace# ./a.out -a
argc=2
argv[0]=./a.out
argv[1]=-a
argv[2]=(null)
root@ubuntu:~/eclipseworkspace# ./a.out -ab
argc=2
argv[0]=./a.out
argv[1]=-ab
argv[2]=(null)
root@ubuntu:~/eclipseworkspace# ./a.out -a b
argc=3
argv[0]=./a.out
argv[1]=-a
argv[2]=b
argv[3]=(null)
root@ubuntu:~/eclipseworkspace# ./a.out -a -b
argc=3
argv[0]=./a.out
argv[1]=-a
argv[2]=-b
argv[3]=(null)


*/
posted @ 2012-09-20 15:27  helloweworld  阅读(335)  评论(0编辑  收藏  举报