Faced with the usage of getchar()(EX1_8-EX_11; TBS1-4)

  To make full use of final long vacation, I decide to read the classical book of C programming book: THE C PROGRAMMING LANGUAGE. Due to its high practical, I will finish every exercises , refer to keys to them and make some analysis. Doing is better than saying, I have finished ex1_8-ex1_11 and have some problems. The whole practice is under Fedora 14.

      First of all, I found that the color of keyword will not be displayed when missing the proper suffix. For example, if I use vim ex1_8 instead of vim ex1_8.c, the keywords wil not be properly colored. The version of my VIM is 7.3.56 and I do not agree that filenames take effect under Linux circumstanes.(TBS.1)

  Then, this problem is from ex1_9 on the page 20. The question is that wirite a program to copy its input to its output, replacing each string of one or more blanks by a single blank.  I decided to use an array variable temp[] to save data from getchar(), to give data to putchar(). The first part about getting data is below:

     while(done == 0){

        src = getchar();

        temp[count] = src;

        if(src == EOF)

          done = 1;

        count++:

     }

    ......

  When typing Enter or Ctrl+D, I found that the program just execute its loop without checking the judgment 'done’. If I change the whole program into a clear type, the probelm will be solved:

    ......

    while((src = getchar()) != EOF)

    ......

      I think the problem is the misunderstanding of the process of getchar(). With further learning, I will find the answer.(TBS.2) Another problem is that some messy code will appear if I remove the particular number of the definition of array variable, like char temp[]={} instead of temp[100]={};(TBS.3)

  The last problem is from exe1_10. Write a program to copy its input to its output, replacing each tab by \t, each back by \b, and each backslach by \\. Even the reference answers can not display the trace of backslach(TBS.4)

   

转载于:https://www.cnblogs.com/youyouzhu-home/archive/2011/08/05/2128997.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值