C程序设计语言习题解答

1-6

#include <stdio.h>
int main(void)
{
printf("getchar()!=EOF is:%d\n", getchar()!=EOF);
return 0;
}

  

编译后
当输入
Ctrl+D
的时候,输出:
getchar()!=EOF is: 0

输入其他值时,输出
getchar()!=EOF is: 1

1-7

 

#include <stdio.h>
int main(void)
{
    printf("EOF is :%d\n", EOF);
    return 0;
}

  

 

编译运行后,输出
EOF is :-1

// 1-8

// 1-8
#include <stdio.h>
/* count '\n','\t, and space in put */
main()
{
    int c;
    int ncount, tcount, scount;
    
    ncount = 0;
    tcount = 0;
    scount = 0;

    while((c = getchar()) != EOF)
    {

        if (c == '\n')
        {
            ++ncount;
        }
        else if (c == '\t')
        {
            ++tcount;
        }
        else if (c == ' ')
        {
            ++scount;
        }
    }
    printf("ncount=%d, tcount=%d, scount=%d\n", ncount, tcount, scount);
}

  

 

//1-9

posted @ 2014-12-12 10:41  drfxiaoliuzi  阅读(310)  评论(0编辑  收藏  举报