Created
February 8, 2025 09:49
-
-
Save krishanthecoder/b642309a79b30a14467a4a8e2fa01086 to your computer and use it in GitHub Desktop.
Count blanks, tabs and newlines in c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) | |
{ | |
int c; | |
int blanks, tabs, newlines; | |
/* Set all count variables to 0 */ | |
blanks = tabs = newlines = 0; | |
while ((c = getchar()) != EOF) | |
{ | |
/* here ' ' represents a blank */ | |
if (c == ' ') | |
{ | |
++blanks; | |
} | |
else if (c == '\t') | |
{ | |
++tabs; | |
} | |
else if (c == '\n') | |
{ | |
++newlines; | |
} | |
} | |
printf("You have entered %d blanks, %d tabs and %d newlines\n", blanks, tabs, newlines); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment