Thread: No print

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    29

    No print

    Dose anyone know why this program will not print for me?

    Thanks

    Code:
    #include <stdio.h>
    #include <ctype.h>
    int main(void)
    {
       char c;
       int low_ct = 0;
       int up_ct = 0;
       int punc_ct = 0;
       int dig_ct = 0;
       int n_words = 0;
       bool inword = false;
    
       printf("Enter text to be analyzed (EOF to terminate):\n");
       while ((c = getchar()) != EOF)
       {
            if (islower(c))
               low_ct++;
            else if (isupper(c))
               up_ct++;
            else if (isdigit(c))
               dig_ct++;
            else if (ispunct(c))
               punc_ct++;
          if (!isspace(c) && !inword)
          {
             inword = true;
             n_words++;
          }
          if (isspace(c) && inword)
             inword = false;
       }
       printf("\nwords = %d, lowercase = %d, uppercase = %d, "
              "digits = %d, punctuation = %d\n",
               n_words,low_ct,up_ct, dig_ct, punc_ct);
               
    
       return 0;
    }

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Did you enter "EOF"? That's usually Ctrl-Z or Ctrl-D.

    gg

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    29
    Quote Originally Posted by Codeplug View Post
    Did you enter "EOF"? That's usually Ctrl-Z or Ctrl-D.

    gg
    Thanks

    Sorry stupid Question forgot to do that problem solved.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    You'll also want to make your c variable an int, not a char. It seems a bit counterintuitive, but since getchar() must be able to return all possible char values plus a signal on end-of-file, a larger type has to be used (for nitpickers, yes, int and char can be the same size, but generally that's not relevant).

    Using char can cause EOF to be signalled early; on a lot of implementations the ÿ character (that's a y-diaeresis if it doesn't come through) will look like EOF. Or it's possible for EOF never to be signalled!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 05:07 PM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  4. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM