CFanatic

Go Back   CFanatic > Programming > C Programming > Advance C


  #1  
Old 01-09-2008, 05:20 PM
Junior Member
 
Join Date: Jan 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
new4c is on a distinguished road
| More
Writing a program that reads input as a stream of characters until EOF

[/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]

Last edited by shabbir; 01-09-2008 at 10:17 PM. Reason: Code block
Reply With Quote
  #2  
Old 01-10-2008, 10:22 AM
Junior Member
 
Join Date: Aug 2007
Location: East Coast USA
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
HowardL is on a distinguished road
| More
Re: Writing a program that reads input as a stream of characters until EOF

Quote:
not getting what I'm expecting
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.

Last edited by HowardL; 01-10-2008 at 10:58 AM.
Reply With Quote
  #3  
Old 05-30-2008, 02:56 PM
Banned
 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
KaiyureBoy is on a distinguished road
| More
Unhappy Yep, thanks, thats good idea.

I tried some possibilities ( etc.) but with no success.

Last edited by shabbir; 05-31-2008 at 05:36 AM. Reason: Link dropped
Reply With Quote
  #4  
Old 05-31-2008, 01:38 PM
Junior Member
 
Join Date: May 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
sherma20 is on a distinguished road
| More
Re: Writing a program that reads input as a stream of characters until EOF

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help in urgent...(file stream) kslpeter87 C++ Programming 1 07-31-2008 05:34 PM
data from input device AlsoPenCover C++ Programming 0 12-12-2007 11:16 PM
Asking input file condition statement kslpeter87 C++ Programming 5 09-23-2007 09:03 PM
writing a spooler ChristophKukulies Win32 Programming 0 09-30-2006 06:54 PM

 

Follow CFanatic on Twitter
CFanatic Search
Custom Search

Advertisement

Go4Expert's Job Board
Powered by

Go4Expert Newsletter
Enter your Name and Email Address below and Click Subscribe.

Subscriber Counter

Not planning to subscribe yet, browse Go4Expert's Newsletter Archive

All times are GMT -5. The time now is 03:33 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Looking for work in C, C++, C#? Sign up at Elance and search over 30,000 Freelancing jobs today.