Thread: I need help counting letters., folk!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    28
    getchar() reads a character from the standard input, usually the
    keyboard. getchar will also 'echo" the typed character to the standard output, usually the user screen.


    I couldn't tell exactly how you wanted this program to work but here's an example.


    Code:
    #include <stdio.h>
    
    int main(void)
    {
      int char_count = 0;
      char next_char = '\0';
    
      printf(" Enter characters but not the # sign <>");
      for(;;)
      {
        next_char = getchar();
        switch(next_char)
       {
        case 'a': case 'b': case 'c':
        char_count++;
        printf(" a,b,c count = %d\n", char_count);
        break;
    
        default: break;
       } // end switch(next_char)
    
       if(next_char == '#')
       {
        puts(" I said not to enter the # sign!");
        break;
      } // end if(next_char == '#')
     } // end for(;;)
    } // end int main(void)
    Last edited by jerryvtts; 07-15-2002 at 12:07 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. counting letters in string
    By CGbiginner in forum C Programming
    Replies: 1
    Last Post: 03-31-2008, 11:47 AM
  2. Counting uppercase and lowercase letters in a text
    By Tintu in forum C Programming
    Replies: 2
    Last Post: 02-06-2008, 10:15 PM
  3. Counting letters and digits
    By FeNCinGeR in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2006, 11:39 AM
  4. Help with counting letters
    By hpy_gilmore8 in forum C++ Programming
    Replies: 3
    Last Post: 10-24-2003, 03:49 PM
  5. Counting letters in window
    By Soldier in forum C++ Programming
    Replies: 3
    Last Post: 03-29-2002, 11:34 PM