Hey ppls am going to study computer science in Jan but am trying to learn the
fundamentals for C,
Code:
int main(){
int c, white, other, i;
int digit[10];
white = other = 0;
for(i = 0; i <10; i++){
digit[i] = 0;
}
while((c = getchar())!=EOF){
if(c >= '0' && c <= '9'){
++digit[c-'0'];
}
else if(c == ' '|| c == '\t'|| c == '\n'){
++white;
}
else{
++other;
}
}
for(i = 0; i < 10; i++){
printf("%d ",digit[i]);
}
printf(" \n%d\n%d",white,other);
return(0);
}
so this code i understand what it does and how it does it but the ++digit[c-'0']
i dont get. I know its adding one to digit array but what does c-'0' mean,
does c equal the char 0 or is it c minuz the char 0 or what am confused.