// c.cpp int main(int argc, char* argv[]) { char s0[30], s1[30]; int ret; for (int i=argc-1; i>0; i--) { s0[0] = s1[0] = 0; //sscanf(argv[i], "%*[^:]:%s", s0); //[^:]代表在':'處設斷點但不包含':', '*'代表忽略'%'起始的字串 sscanf(argv[i], "-%29[^:]:%29s", s0, s1); if (s0[0] == 0 || s1[0] == 0) puts("Wrong type!"); else printf("%s : %s\n", s0, s1); } return 0; }
----------------------Output---------------------------
> g++ -o c c.cpp
> c -name:John -age:20
age : 20
name : John
沒有留言:
張貼留言