- 论坛徽章:
- 0
|
linux程序设计书上抄的。 两个地方不明白。 求助,谢谢
- #include <stdio.h>
- #include <unistd.h>
- int main(int argc, char *argv[]) {
- int opt; //为什么是"int"型,而我换了"char"型也可以
- while((opt=getopt(argc, argv, "if:lr")) != -1) {
- switch(opt) {
- case "i": /*换成双引号,出错
- 提示:“case label does not reduce to an interger constant”*/
- case 'l':
- case 'r': printf("option : %c\n", opt);
- break;
- case 'f': printf("filename : %s\n", optarg); break;
- case ':': printf("option need a value!\n"); break;
- case '?': printf("unknown option!\n"); break;
- }
- }
- for(; optind<argc; optind++)
- printf("argument : %s\n", argv[optind]);
- exit(0);
- }
复制代码 |
|