Skip to content

Instantly share code, notes, and snippets.

@krishanthecoder
Created February 8, 2025 09:49
Show Gist options
  • Save krishanthecoder/b642309a79b30a14467a4a8e2fa01086 to your computer and use it in GitHub Desktop.
Save krishanthecoder/b642309a79b30a14467a4a8e2fa01086 to your computer and use it in GitHub Desktop.
Count blanks, tabs and newlines in c
#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