Exercise 1-8 in C by Kernighan and Ritchie
void countBlanksTabsNewlines() {
int c, newLines, tabs, blanks;
newLines = 0;
tabs = 0;
blanks = 0;
while ((c = getchar()) != EOF){
if (c == '\n'){
++newLines;
} else if(c == '\t'){
++tabs;
} else if(c == ' '){
++blanks;
}
}
printf("New Lines = %d , Tabs = %d , Blanks == %d", newLines, tabs, blanks);
}
When I use any input then press enter, the while loop doesn't terminate. My code is based off the example counting just new lines from the book, so not sure how to solve. Thanks :)
Edit: I failed to mention I am using CLion IDE and after trying the shortcuts suggested here in CLion (unsuccessfully), I tried doing the same in an online compiler and ctrl+D worked.