免费注册 查看新帖 |

Chinaunix

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

《Unix/Linux编程实践教程》教材中问题。。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-05-16 17:45 |只看该作者 |倒序浏览
本帖最后由 sz6180 于 2011-05-16 20:06 编辑
  1. /* more01.c  - version 0.1 of more
  2. *        read and print 24 lines then pause for a few special commands
  3. */

  4. #include        <stdio.h>

  5. #define        PAGELEN        24
  6. #define        LINELEN        512

  7. void do_more(FILE *);
  8. int  see_more();

  9. int main( int ac , char *av[] )
  10. {
  11.         FILE        *fp;

  12.         if ( ac == 1 )
  13.                 do_more( stdin );
  14.         else
  15.                 while ( --ac )
  16.                         if ( (fp = fopen( *++av , "r" )) != NULL )
  17.                         {
  18.                                 do_more( fp ) ;
  19.                                 fclose( fp );
  20.                         }
  21.                         else
  22.                                 exit(1);
  23.         return 0;
  24. }

  25. void do_more( FILE *fp )
  26. /*
  27. *  read PAGELEN lines, then call see_more() for further instructions
  28. */
  29. {
  30.         char        line[LINELEN];
  31.         int        num_of_lines = 0;
  32.         int        see_more(), reply;

  33.         while ( fgets( line, LINELEN, fp ) ){                /* more input        */
  34.                 if ( num_of_lines == PAGELEN ) {        /* full screen?        */
  35.                         reply = see_more();                /* y: ask user  */
  36.                         if ( reply == 0 )                /*    n: done   */
  37.                                 break;
  38.                         num_of_lines -= reply;                /* reset count        */
  39.                 }
  40.                 if ( fputs( line, stdout )  == EOF )        /* show line        */
  41.                         exit(1);                        /* or die        */
  42.                 num_of_lines++;                                /* count it        */
  43.         }
  44. }

  45. int see_more()
  46. /*
  47. *        print message, wait for response, return # of lines to advance
  48. *        q means no, space means yes, CR means one line
  49. */
  50. {
  51.         int        c;

  52.         printf("\033[7m more? \033[m");                /* reverse on a vt100        */
  53.         while( (c=getchar()) != EOF )                        /* get response        */
  54.         {
  55.                 if ( c == 'q' )                        /* q -> N                */
  56.                         return 0;
  57.                 if ( c == ' ' )                        /* ' ' => next page        */
  58.                         return PAGELEN;                /* how many to show        */
  59.                 if ( c == '\n' )                /* Enter key => 1 line        */
  60.                         return 1;               
  61.         }
  62.         return 0;
  63. }
复制代码
在这本书的第一章,我像书上一样写了个more01.c的程序。运行得到more01可执行文件。但是在命令行输入
($more01 more01.c)并没有内容出来。为什么啊?是不是要把more文件放到哪个目录下?还是说我写错了,小弟刚入linux,有很多不懂的,望大侠们指教。

论坛徽章:
0
2 [报告]
发表于 2011-05-16 18:10 |只看该作者
more more01.c有没有错误提示?

论坛徽章:
0
3 [报告]
发表于 2011-05-16 20:07 |只看该作者
more more01.c有没有错误提示?
whaaat 发表于 2011-05-16 18:10



    是more01 more01.c

论坛徽章:
0
4 [报告]
发表于 2011-05-16 20:27 |只看该作者
回复 3# sz6180
搞错了。那你more01 more01.c有什么错误提示?./more01 more01.c试试呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP