A "bug" in my counting vowels C program. Need advice, please help.
Dear CProgramming administrators and members:
Good day everyone. I hope everybody is in good health upon reading this thread. Well, here's the code I've done recently (just sort of trying though):
Code:
#include<stdio.h>
#include<ctype.h>
#define ENTERKEY '\r'
int main(){
char buff[80];
char letter;
char temp[80];
int count=0;
clrscr();
printf("Please enter characters:");
do{
letter = getche();
letter = toupper(letter);
if((letter=='A') | (letter=='E') | (letter=='I') | (letter=='O') | (letter=='U'))
count++;
else
continue;
}while(letter != ENTERKEY);
printf("\n\nYou entered %d vowel letters.", count);
getch();
return 0;
}
The output seems fine, example, if I type apple then the output is You entered 2 vowel letters....but when I press Backspace, example I change my input to banana, then I noticed it just added the previous count to the vowels inside banana, Now there are five (5) vowel letters instead of just three (3). And if I press Backspace, the letters didn't erase, it will just be overwritten by my "other" input. I know the problem relies on the count if the program detected an A, E, I, O, U on the input, but I'm kind of stuck to the program, I mean, everytime I change leads to error, so I just hoping by consulting from this forum will help me how to solve my bugs, I will really appreciate any change you might feel on the code.
Thank you so much guys and God bless everyone.
Respectfully yours,
MarkSquall
Thank you guys for the information.
Dear tabstop and Salem,
Thank you for the information you gave, I guess getch() is a NO-NO on my program, I'll try to change this based on your suggestions, but if someone is willing (just in case), I hope someone would correct my code in this thread, but I will also do what can I do.
Thanks everyone. I really appreciate your comments/suggestions.
Respectfully Yours,
MarkSquall
Thanks guys for the information...
Dear members and administrators,
Thank you Mr. Salem for the fgets() function and the bitwise and logical OR, actually I didn't know what their difference until I research on them. I "fixed" my own bugs. Sigh...such a nice feeling. Thanks everyone. More to hear from you all.
God bless you all.
Respectfully Yours,
MarkSquall