counting letters and sequence

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • euniceno1
    New Member
    • Oct 2006
    • 11

    counting letters and sequence

    I am just learning c language at the moment, i have problem with following program:
    #define TRUE 1
    #define FALSE 0
    #define MAX_LENGTH 100000 /* Max number of chars read from file */
    #include <stdio.h>
    #include <ctype.h>

    int Get_String_From _File(char filename[], char input[])
    /* Reads in characters (including \n) from a file as one long string */
    /* filename should give name of an existing file;
    input will return contents of that file */
    /* Return value 0 if file open fails, 1 otherwise */
    /* Maximum length of string is stored in MAX_LENGTH */

    {
    int i = -1; /* will be updated before being used */
    char temp;
    FILE *infile;

    infile = fopen(filename, "r");
    if (infile == NULL) {
    printf("Failed to open file \"%s\"\n",filen ame);
    return FALSE;
    }

    do {
    i++;
    input[i] = fgetc(infile);
    } while (input[i] != EOF && i < MAX_LENGTH - 1 && input[i] != '\0');
    if (i == MAX_LENGTH - 1) /* only reason for stopping is MAX_LENGTH */
    fprintf(stderr, "Warning: Reached maximum size of file handled by this program!\n\n");
    input[i] = '\0'; /* end of string marker*/
    fclose(infile);

    return TRUE; /* Successfully read file */
    }
    int main(void)
    {
    int c, i, j, letter[26][26];

    for (i=0; i<26; ++i) /* init array to zero */
    letter[i] = 0;
    for( j= 0; j<26; ++j)
    letter[j] = 0;
    while((c = getchar()) != EOF) /* count the letter */
    if(isupper(c) && islower(c))
    ++letter[c -> 'A' && c -> 'a'];
    for (i=0; i<26; ++i)
    if(i%6==0)
    for ( j= 0; j<26; ++j)
    if(j%6==0) {
    printf("\n");
    printf("%4c%4c: %3d%3d", 'A' || 'a' +i +j, letter[i][j]);
    }
    printf("\n\n");
    return 0;
    }
  • vermarajeev
    New Member
    • Aug 2006
    • 180

    #2
    Please let us know what is the problem.

    Thankx

    Comment

    • euniceno1
      New Member
      • Oct 2006
      • 11

      #3
      the problem is to count the letters and sequence from a file. the fist thing of my code is to read file and in the main function i create is to count the characters and sequence by using 2 dimension array.
      where the character include letters and spaces.

      Comment

      Working...