#include<stdio.h> #include<string.h> int main(int argc,char *argv[])//同int main(int argc,char **argv) { char *str_test = "hello wang"; int i,j,len; for(i=0;i<argc;i++) { printf("argv%d is %s ",i,argv[i]); len = strlen(argv[i]); printf("len = %d ",len); for(j=0;j<len;j++) { printf("argv%d%d is %c ",i,j,argv[i][j]); } } printf("str_test = %s ",str_test); printf("str_test = %c ",str_test[1]); return 0; }
//argv:字符串数组,内容为指向字符串的指针(argv[0],argv[1],argv[2])
//argv[0],argv[1],argv[2]分别指向第1,2,3个字符串的指针
//argv[0][i],argv[1][i],argv[2][i]分别为第1,2,3个字符串中的第i个字符
//strlen():计算的是字符串实际个数(长度),不包括' ',遇到第一个' '结束.如果你只定义没有给它赋初值,这个结果是不定的,它会从首地址一直找下去,直到遇到' '停止.
//sizeof():返回的是变量声明后所占的内存数(即变量类型的字节数),不是实际长度,此外sizeof不是函数,仅仅是一个操作符,strlen()是函数
//不严格的来看: *str = c[]
**str = *str[] = c[][]
/*wang@wang-X455LJ:~/program_test/c_program_test$ ./test wang cai
argv0 is ./test
len = 6
argv00 is .
argv01 is /
argv02 is t
argv03 is e
argv04 is s
argv05 is t
argv1 is wang
len = 4
argv10 is w
argv11 is a
argv12 is n
argv13 is g
argv2 is cai
len = 3
argv20 is c
argv21 is a
argv22 is i
str_test = hello wang
str_test = e*/