7.12.1

# 7.12.1
#include <stdio.h>
int main(void)
{
    char ch;
    int space_count = 0;
    int linebreak_count = 0;
    int other_count = 0;

    while ((ch = getchar()) != '#')
    {
        if (ch == ' ')
            space_count++;
        else if (ch == '
')
            linebreak_count++;
        else
            other_count++;
    }
    printf("space is %d, line break is %d, other char is %d
",
                    space_count, linebreak_count, other_count);

    printf("Done!
");
    return 0;
}





# 7.12.1  other version
#include <stdio.h>
int main(void)
{
    char ch;
    int space_count = 0;
    int linebreak_count = 0;
    int other_count = 0;

    while ((ch = getchar()) != '#')
    {
        if (ch == ' ')
            space_count++;
        if (ch == '
')
            linebreak_count++;
        if ((ch != ' ') && (ch != '
'))
            other_count++;
    }
    printf("space is %d, line break is %d, other char is %d
",
                    space_count, linebreak_count, other_count);

    printf("Done!
");
    return 0;
}
原文地址:https://www.cnblogs.com/EisNULL/p/10753842.html