[/SIZE]Writing a program that reads input as a stream of characters until encountering EOF. Have it report the number of uppercase letters and the number of lowercase letters in the input. [/SIZE] Here is what I tried but not getting what I'm expecting. Please help me point out why. Thanks a lot Code: #include<stdio.h> #include<ctype.h> int main() { // Local Declarations char ch; int locnt, u; int upcnt, l; int index; // Statements printf(" Please enter an uppercase or lowercase letter:\n"); while ( (ch = getchar())!= EOF) { if(isupper(ch)) { for (u = 0; u <= ch; u ++) upcnt++; printf(" The number of uppercase entered is:\n", upcnt); } else (islower(ch)); for ( l = 0; l <= ch; l++) locnt++; printf(" The number of uppercase entered is:\n", locnt); }//while fflush(stdin); getchar(); return 0; }//main [/SIZE]
So what were you getting? Show some output. Explain how it differs from what you were expecting... You have several things wrong there,, each a mini-discussion in itself. 'Build' your code in steps. Test as you go. Then you will see EXACTLY what causes these problems. You can solve them as you go along. You will learn better habits and not repeat the same things as much. I would suggest that you drop back and rebuild that from the beginning. Start with only the variables and statements needed for the first thing say the getchar() loop. A couple of notes in that regard: Code: while ( (ch = getchar()) != EOF ) /* looking for EOF to come from stdin causes endless loop for me in win32 (not sure about linux) try : '\n' ...that is sent when we press the "ENTER" key */ /**********/ /* fflush(stdin); ***fflush() is intended for stdout, */ /* ....for an effective pause/flush try this instead: */ while( getchar() != '\n') Post back progress and next problem.
I did'nt read your whole program when I saw that you did not put a scanf just after you asked for the letter. Do that then see what you get