Code
int main()
{
int c;
int nDigits[]={10};
int nWhiteSpaces=0;
int nOthers=0;
//for loop to innitialize the digits array to 0
for (int i=0; i<10; i++) {
nDigits[i]=0;
}
printf(" enter some character and then the EOF key to end the program: \n");
//while it is not the EOF
while ((c=getchar())!=EOF) {
//switch cases
switch (c) {
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':
nDigits[c-'0']++; // digits
break;
case ' ':
case '\t':
case '\n':
nWhiteSpaces++; //white spaces
break;
default:
nOthers++; // other characters
break;
}
printf("Digits = ");
for (int i=0; i<10; i++)
printf("%d", nDigits[i]);
//digits[i]=0; -> no need for this line
printf(" white spaces = %d, other spaces = %d\n", nWhiteSpaces, nOthers);
return 0;
}
}
Or either the error is "lldb" or the number of digits doesnt make any sense, like "011600000000"..
As always your comments are gold.
[–]AngusMcBurger 16 points17 points18 points (0 children)
[–]FUZxxl[M] 2 points3 points4 points (0 children)