So I'm new in C language and I'm trying to do a histogram with the length of the words the user typed, I have a solution but my second for loop always fail, I code like 5 for loop and every of them just stop after the second or third iteration, Am I missing something please help. Here's my code.
#include<stdio.h>
int main(){
int i,x,c,r,size;
int wa[10];
size=0;
for(i=0;i<10;i++){
wa[i]=0;
}
while((c=getchar())!=EOF){
switch(c){
case' ':{
wa[size]++;
size=0;
break;}
case'\n':{
wa[size]++;
size=0;
break;}
case'\t':{
wa[size]++;
size=0;
break;}
default:{
size++;
break;
}
}
}
for(r=0;r<=10;++r){
printf("%d",r);
for(x=0;x<wa[r];x++){
printf("*");
}
printf("\n");
}
return 0;
}
wa[4]special? I guess thatdefaultis executed when letters are found but still it's unclear.