- 论坛徽章:
- 1
|
我以前临摹的一个 hello world。
大家看了以后不要说我无聊,我无聊是因为有人无聊在先:
http://packages.debian.org/unstable/devel/hello
2007.12.14 又改进了一下。
- /*
- * $Id$
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <getopt.h>
- int
- main( int argc, char *argv[] )
- {
- int c;
- while (1) {
- int option_index = 0;
- static struct option long_options[] = {
- { "help", 0, 0, 'h' },
- { "version", 0, 0, 'v' },
- { "traditional", 0, 0, 't' },
- { "next-generation", 0, 0, 'n' },
- { 0, 0, 0, 0 }
- };
- c = getopt_long( argc, argv, "hvtn",
- long_options, &option_index );
- if (c == -1)
- break;
- switch (c) {
- case 'h':
- printf( "``hello'' is a greeting program which wrote by flw.\n"
- "\n"
- "Usage: hello [OPTIONS]\n"
- " -h, --help display this message then exit.\n"
- " -v, --version display version information then exit.\n"
- "\n"
- " -t, --traditional output a greeting message with traditional format.\n"
- " -n, --next-generation output a greeting message with next-generation format.\n"
- "\n"
- "Report bugs to <[email]flw@cpan.org[/email]>\n"
- );
- break;
- case 'v':
- printf( "hello - flw's hello world. 0.8 version\n" );
- break;
- case 't':
- printf( "hello, world\n" );
- break;
- case 'n':
- printf(
- "+---------------+\n"
- "| Hello, world! |\n"
- "+---------------+\n"
- );
- break;
- default:
- break;
- }
- }
- if ( optind < argc ){
- fprintf( stderr,
- "Too many arguments\n"
- "Try `hello --help' for more information.\n"
- );
- exit( EXIT_FAILURE );
- }
- if ( optind == 1 ){
- printf( "Hello, world!\n" );
- }
- exit ( EXIT_SUCCESS );
- }
复制代码
[ 本帖最后由 flw 于 2007-12-20 16:40 编辑 ] |
|