Skip to content

Instantly share code, notes, and snippets.

@cynx
Created June 9, 2014 17:16
Show Gist options
  • Save cynx/b40ef6988eefe2e95d4c to your computer and use it in GitHub Desktop.
Save cynx/b40ef6988eefe2e95d4c to your computer and use it in GitHub Desktop.
C Program to count occurance of digits and white space and others
//to count occurance of digits and white space and others
#include <stdio.h>
int main()
{
int i,c,nwhites,nothers;
int ndigits[10];
c=nwhites=nothers=0;
for (i=0; i<10; ++i) {
ndigits[i]=0;
}
while ((c=getchar())!=EOF) {
if(c>='0' && c<='9')
{
++ndigits[c-'0'];
} else if (c == ' ' || c == '\n' || c == '\t')
++nwhites;
else
++nothers;
}
for(i=0;i<10;++i)
printf(" %d",ndigits[i]);
printf("\n%d %d",nwhites,nothers);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment