免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1462 | 回复: 3
打印 上一主题 下一主题

[C] getopt_long函数使用问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-03-19 17:56 |只看该作者 |倒序浏览
  1. #include <stdio.h>
  2. #include <getopt.h>
  3. #include <stdlib.h>

  4. const char * program_name;

  5. void print_usage(FILE *stream, int exit_code)
  6. {
  7.         fprintf(stream, "Usage: %s option [outputs]\n", program_name );
  8.         exit(exit_code);
  9. }

  10. int main(int argc, char const *argv[])
  11. {
  12.         /* code */
  13.         program_name = argv[0];
  14.         int next_option;
  15.         static struct option const long_option[] =
  16.         {
  17.                 {"help",        0, NULL, 'h'},
  18.                 {"output",        1, NULL, 'o'},
  19.                 {"verbose",        0, NULL, 'v'},
  20.                 {NULL, 0, NULL, 0}
  21.         };

  22.         while( (next_option = getopt_long(argc, argv, "ho:v", long_option , NULL)) != -1)
  23.         {
  24.                 switch(next_option)
  25.                 {
  26.                         case 'h':
  27.                                 print_usage(stdout, 0);
  28.                                 break;
  29.                         case 'o':
  30.                                 print_usage(stdout, 0);
  31.                                 break;
  32.                         case 'v':
  33.                                 print_usage(stdout, 0);
  34.                                 break;
  35.                         default:
  36.                                 print_usage(stdout, 0);
  37.                                 break;
  38.                 }
  39.         }
  40.         return 0;
  41. }
复制代码
各位帮忙看看,哪里出错了,一直编译不通过!

论坛徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46处女座
日期:2013-10-24 14:25:01酉鸡
日期:2014-04-07 11:54:15
2 [报告]
发表于 2013-03-19 18:01 |只看该作者
int main(int argc, char const *argv[])

改为

int main(int argc, char *const argv[])

论坛徽章:
0
3 [报告]
发表于 2013-03-19 18:13 |只看该作者
回复 2# linux_c_py_php



哇,一眼就看出问题了,佩服!俺什么时候能达到这水准呢,呵呵
能说说 这两中写法,有什么区别吗?


谢谢


   

论坛徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46处女座
日期:2013-10-24 14:25:01酉鸡
日期:2014-04-07 11:54:15
4 [报告]
发表于 2013-03-19 21:48 |只看该作者
指针基础, 没法言传...
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP