Text Analysis/assign3.c
void letterAnalysis(char **bufferPtr, int numOfLines){
    puts("");
    const char *alphabet = "abcdefghijklmnopqrstuvwxyz";
    
    //makes a copy of the original data to avoid data destruction
    char copy[MAX_LINES * MAX_LINE_LENGTH];   
    make1DArrayFrom2D(copy, bufferPtr, numOfLines);

    //converts all convertable characters to lowercase
    for(unsigned int j = 0; (copy[j]) != '\0'; j++){
        if(isalpha((copy[j]))){
            (copy[j]) = tolower((copy[j]));
        }
    }

    //searches for occurrences of letters
    for(unsigned int j = 0; alphabet[j] != '\0'; j++){ 
        int count = 0;
        char *str = strchr(copy, alphabet[j]);;
        while(str != NULL){
            count++;
            str = strchr(str+1, alphabet[j]);
        }
        
        if(j % 5 == 0) puts("");
        printf("%c : %3d   ", alphabet[j], count);
    }
    
    puts("");
}
/*
    letterAnalysis: analyses the number of occurrences of each letter in the text and prints the results
    input: an array of text (bufferPtr), the number of lines to be analysed (numOfLines)
*/
analyses the number of occurrences of each letter in the text and prints the results
input: an array of text (bufferPtr), the number of lines to be analysed (numOfLines)
analyses the number of occurrences of each letter in the text and prints the results input : an array of text ( bufferPtr ) the number of lines to be analysed ( numOfLines )
void letterAnalysis(char **bufferPtr, int numOfLines){
    puts("");
    const char *alphabet = "abcdefghijklmnopqrstuvwxyz";
    char copy[MAX_LINES * MAX_LINE_LENGTH];   
    make1DArrayFrom2D(copy, bufferPtr, numOfLines);
    for(unsigned int j = 0; (copy[j]) != '\0'; j++){
        if(isalpha((copy[j]))){
            (copy[j]) = tolower((copy[j]));
        }
    }
    for(unsigned int j = 0; alphabet[j] != '\0'; j++){ 
        int count = 0;
        char *str = strchr(copy, alphabet[j]);;
        while(str != NULL){
            count++;
            str = strchr(str+1, alphabet[j]);
        }
        if(j % 5 == 0) puts("");
        printf("%c : %3d   ", alphabet[j], count);
    }
    puts("");
}
void letterAnalysis ( char * * bufferPtr , int numOfLines ) { puts ( " " ) ; const char * alphabet = " " ; char copy [ MAX_LINES * MAX_LINE_LENGTH ] ; make1DArrayFrom2D ( copy , bufferPtr , numOfLines ) ; for ( unsigned int j = 0 ; ( copy [ j ] ) != ' \0 ' ; j ++ ) { if ( isalpha ( ( copy [ j ] ) ) ) { ( copy [ j ] ) = tolower ( ( copy [ j ] ) ) ; } } for ( unsigned int j = 0 ; alphabet [ j ] != ' \0 ' ; j ++ ) { int count = 0 ; char * str = strchr ( copy , alphabet [ j ] ) ; ; while ( str != NULL ) { count ++ ; str = strchr ( str + 1 , alphabet [ j ] ) ; } if ( j % 5 == 0 ) puts ( " " ) ; printf ( " " , alphabet [ j ] , count ) ; } puts ( " " ) ; }
letterAnalysis: analyses the number of occurrences of each letter in the text and prints the results
input: an array of text (bufferPtr), the number of lines to be analysed (numOfLines)
letterAnalysis : analyses the number of occurrences of each letter in the text and prints the results input : an array of text ( bufferPtr ) the number of lines to be analysed ( numOfLines )
//makes a copy of the original data to avoid data destruction //converts all convertable characters to lowercase //searches for occurrences of letters