Write a program to count blanks, tabs, and newlines. - C Data Type

C examples for Data Type:char

Description

Write a program to count blanks, tabs, and newlines.

Demo Code

#include <stdio.h>

int main(void){
    int c, bl, tl, nl;
    bl = 0;//from w ww. j a v a2 s.c om
    tl = 0;
    nl = 0;

    printf("Input some characters, then press Ctrl+D.\n");
    while ((c = getchar()) != EOF){
        if (c == ' ')
            ++bl;
        else if (c == '\t')
            ++tl;
        else if (c == '\n')
            ++nl;
}
    printf("Count of blanks is %d, count of tabs is %d, count of newlines is %d.\n", bl, tl, nl);

    return 0;
}

Result


Related Tutorials