Skip to content

Instantly share code, notes, and snippets.

@funrep
Created September 26, 2012 17:52
Show Gist options
  • Save funrep/3789494 to your computer and use it in GitHub Desktop.
Save funrep/3789494 to your computer and use it in GitHub Desktop.
asdfad
#include <stdio.h>
/* count digits, white space, others */
main()
{
int c, i, nwhite, nother;
int ndigit[10]; /* this declares an array with 10 variables in it? */
nwhite = nother = 0;
for (i = 0; i < 10; ++i)
ndigit[i] = 0;
while ((c = getchar()) != EOF)
if (c >= '0' && c <= '9')
++ndigit[c-'0']; /* c - '0' is to get right char/ascii thing, but i still not understand which ndigitit declares too, is it ndigit[1]? or ndigit[2]? etc.... */
else if (c == ' ' || c == '\n' || c == '\t')
++nwhite;
else
++nother;
printf("digits =");
for (i = 0; i < 10; ++i)
printf(" %d", ndigit[i]); /*ndigit[i] == what?, i dont understand */
printf(", white space = %d, other = %d\n", nwhite, nother);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment