免费注册 查看新帖 |

Chinaunix

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

超强 Hello World [复制链接]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-20 10:11 |只看该作者 |倒序浏览
我以前临摹的一个 hello world。
大家看了以后不要说我无聊,我无聊是因为有人无聊在先:
http://packages.debian.org/unstable/devel/hello

2007.12.14 又改进了一下。
  1. /*
  2. * $Id$
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <getopt.h>

  7. int
  8. main( int argc, char *argv[] )
  9. {
  10.     int c;

  11.     while (1) {
  12.         int option_index = 0;
  13.         static struct option long_options[] = {
  14.             { "help",            0, 0, 'h' },
  15.             { "version",         0, 0, 'v' },
  16.             { "traditional",     0, 0, 't' },
  17.             { "next-generation", 0, 0, 'n' },
  18.             { 0, 0, 0, 0 }
  19.         };

  20.         c = getopt_long( argc, argv, "hvtn",
  21.                 long_options, &option_index );
  22.         if (c == -1)
  23.             break;

  24.         switch (c) {
  25.             case 'h':
  26.                 printf( "``hello'' is a greeting program which wrote by flw.\n"
  27.                         "\n"
  28.                         "Usage: hello [OPTIONS]\n"
  29.                         "       -h, --help             display this message then exit.\n"
  30.                         "       -v, --version          display version information then exit.\n"
  31.                         "\n"
  32.                         "       -t, --traditional      output a greeting message with traditional format.\n"
  33.                         "       -n, --next-generation  output a greeting message with next-generation format.\n"
  34.                         "\n"
  35.                         "Report bugs to <[email]flw@cpan.org[/email]>\n"
  36.                       );

  37.                 break;

  38.             case 'v':
  39.                 printf( "hello - flw's hello world. 0.8 version\n" );
  40.                 break;

  41.             case 't':
  42.                 printf( "hello, world\n" );
  43.                 break;

  44.             case 'n':
  45.                 printf(
  46.                         "+---------------+\n"
  47.                         "| Hello, world! |\n"
  48.                         "+---------------+\n"
  49.                       );
  50.                 break;

  51.             default:
  52.                 break;
  53.         }
  54.     }

  55.     if ( optind < argc ){
  56.         fprintf( stderr,
  57.                 "Too many arguments\n"
  58.                 "Try `hello --help' for more information.\n"
  59.               );
  60.         exit( EXIT_FAILURE );
  61.     }

  62.     if ( optind == 1 ){
  63.         printf( "Hello, world!\n" );
  64.     }

  65.     exit ( EXIT_SUCCESS );
  66. }
复制代码

[ 本帖最后由 flw 于 2007-12-20 16:40 编辑 ]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2007-04-20 10:12 |只看该作者
这个程序是我根据 Debian 的 hello 包的 man 手册所描述的功能,自己实现的。

论坛徽章:
0
3 [报告]
发表于 2007-04-20 10:13 |只看该作者
靠过一次了,我再来靠一次。。。
我靠。

论坛徽章:
0
4 [报告]
发表于 2007-04-20 10:14 |只看该作者
还用了getopt.....

厉害

论坛徽章:
0
5 [报告]
发表于 2007-04-20 10:16 |只看该作者
flw发疯了……

论坛徽章:
3
CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52
6 [报告]
发表于 2007-04-20 10:31 |只看该作者
flw 是 M 还是 F ?

论坛徽章:
3
CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52
7 [报告]
发表于 2007-04-20 10:49 |只看该作者
原帖由 flw 于 2007-4-20 10:33 发表

既不是 father,也不是 mother,事实上我还没有孩子。


  

论坛徽章:
0
8 [报告]
发表于 2007-04-20 10:54 |只看该作者
哈哈

论坛徽章:
0
9 [报告]
发表于 2007-04-20 10:54 |只看该作者
原帖由 flw 于 2007-4-20 10:33 发表

既不是 father,也不是 mother,事实上我还没有孩子。

以前一直以为flw是female,后来听说是male

论坛徽章:
0
10 [报告]
发表于 2007-04-20 10:58 |只看该作者
刚才试了一下,debian的stable源里就有这个程序,apt-get install hello
还有好多选项呢,哈哈,有意思~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP