I've just copied this example from K&R from page 23 but it doesnt works properly:
Code:
#include <stdio.h>
int main(){
int c, i, nwhite, nother;
int ndigit[10];
nwhite = nother = 0;
for (i = 0; i < 10; ++i)
ndigit[i] = 0;
while ((c = getchar()) != EOF)) //I had a missing ) here;
if (c >= '0' && c <= '9')
++ndigit[c-'0'];
else if (c == ' ' || c== '\n' || c == '\t' )
++nwhite;
else
nother++;
printf("digits =");
for (i = 0; i < 10; ++i)
printf("%d", ndigit[i]);
printf(", white space %d, other = %d\n", nwhite, nother);
return 0;
}
Ive replaced EOF for 'q' because I dont know how to "type" EOF, also ive noticed that spaces and other counters seem wrong. Im testing it with linux Gentoo, Ive compiled with gcc -Wall but no messages of warning were shown. Any ideas? Thanks in advance guys.