There is no sticky here so I'll make a questions thread.
I made a program (for an excercise in a book) that draws an histogram of the length of words in a given text.
It works absolutely fine except for one little thing.
here's the full source code: http://pastebin.com/eFjEGA79
here's the relevant part:
while((c=getchar())!=EOF){
if (c!=' '&&c!='\t'&&c!='\n'&&c!='.'&&c!=',')
++teller;
else if(teller>=10){
++woord[10];
if (woord[10]>=maxteller)
maxteller=woord[10];
teller=0;
}
else{
++woord[teller];
if (woord[teller]>=maxteller)
maxteller=woord[teller];
teller=0;
}
}
++woord[teller];
if (woord[teller]>=maxteller)
maxteller=woord[teller];
When I was testing it I made a typing mistake and I hit backspace. Now this made me wonder if that does ++teller (teller is dutch for counter) since every keystroke except ' ' && '\t' && '\n' adds to it. In my reasoning backspace is part of ascii so getchar() 'gets' it and returns 8, which is the decimal integer for it, resulting in c having that value and c returng true to the first if.
tl;dr
hitting backspace to correct a typing mistake does not add to the word length although I didn't specify it do to so and I don't understand why.