Thread: CHARACTER FREQUENCY WITH ARRAYS [EOF not working]

  1. #1
    Registered User
    Join Date
    Aug 2017
    Posts
    28

    CHARACTER FREQUENCY WITH ARRAYS [EOF not working]

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <assert.h>
    
    
    //Frequency table of input
    int main(int argc, char*argv[])
    {
        int counts[26] = {0};
        int cypherChar = getchar();
    
    
        while(cypherChar != EOF)
        {
            if(isalpha(cypherChar))
            {
                counts[tolower(cypherChar) - 97]++;
            }
            cypherChar = getchar();
        }
    
    
        printf("Frequency Table\n");
    
    
        int i = 'a';
        while(i <= 'z')
        {
            printf("%c %d\n", i, counts[i - 'a']);
            i++;
        }
        return 0;
    }

    When I replace EOF with 10(ASCII value for Line Feed) it works fine but with EOF , NO OUTPUT!!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    How do you send EOF?

    At the start of a line, press ctrl-z (dos/wondows), or ctrl-d (unix/linux), then perhaps enter.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Character Frequency Tables from array Etc.
    By paujmos in forum C Programming
    Replies: 3
    Last Post: 11-11-2012, 08:05 PM
  2. Character frequency counting
    By zcrself in forum C Programming
    Replies: 2
    Last Post: 03-01-2010, 11:04 AM
  3. frequency character counter
    By hasanah in forum C Programming
    Replies: 4
    Last Post: 04-15-2009, 01:28 AM
  4. Character frequency table
    By raidkridley in forum C Programming
    Replies: 1
    Last Post: 02-12-2009, 06:31 AM
  5. about program that counts a character frequency
    By Unregistered in forum C++ Programming
    Replies: 15
    Last Post: 04-23-2002, 01:21 PM

Tags for this Thread