The C Programming Language | Exercise 1-8

/*Exercise 1-8*/
#include <stdio.h>

main()
{
    int c,nb,nt,nn;
    c = 0;
    nb = 0;
    nt = 0;
    nn = 0;
    printf ("please enter a paragraph to test its blanks,tabs and newlines");
    while ((c = getchar()) != EOF)
        if (c == ‘ ‘)
                ++nb;
        if (c == ‘\t’)
                ++nt;
        if (c == ‘\n’)
                ++nn;
    printf ("OK,after computing,the pc will tell you there are"
            "%d blank(s) %d tab(s) and %d new line(s)",nb,nt,nn
            );
    system("pause");
}

———————-
我发现我很喜欢重新翻出这一条作业来做!不过,多做以后可以发现很多问题.

1.有关函数的声明
这里采用的方法绝对是最原始最浪费内存的,不过在第二章以后将采用新的方法
2.printf函数中显示的部分双引号内部的信息只能写一行,要是有多行则每行都应该使用一个引号括起来
3.最后一句话system(pause);用于防治程序运行后马上关闭,不过现在还不是很清楚为什么要这样做

Leave a comment