Exercise #1.8

alendr · updated September 15, 2021 · C
#include <stdio.h>
/* Counts blanks, tabs, newlines. */ 
int main() {
    int c, nnl, nb, nt; 
    nnl = 0; /* number of newlines */   
    nb = 0; /* number of blanks */ 
    nt = 0; /* number of tabs */ 
    while ((c = getchar()) != EOF) 
        {if (c == ' ')  
            ++nb; 
         if (c == '\t') 
            ++nt;  
         if (c == '\n') 
            ++nnl;} 
    printf("%d %d %d\n", nb, nt, nnl); 
    return 0;
}

Comments

Please sign up or log in to contribute to the discussion.