arrayscstringmultidimensional-arraypangram

Check whether a list of words make a Pangram


I need to create a 2D string array and input to hi, up to 10 words, than to check if those words are pangram or not.
The program needs to stop receiving words if the words are pangram.
for example:

the
five
boxing
wizards
jump
quickly
It's a pangram?
Yes

but instead of stopping it's just keeps asking for words until it gets to 10. Also says that non-pangram sentences are pangram.

    #include<stdio.h>
    #include <string.h>

     #define ROWS 10
     #define COL 50
     #define NUM_OF_LETTERS 26


     int main()
     {
        char words[ROWS][COL] = {0};
        char used []['z' - 'a' + 1] = {0};
        int i = 0;
        int j=0;
        int count = 0;

        printf("Enter up to 10 words try to make a pangram\n");
        while(i<ROW&& count < NUM_OF_LETTERS)
        {
            fgets(words[i], ROW, stdin);
            words[i][strcspn(words[i], "\n")] = 0;
            int len = strlen(words[i]);
        
            for(j=0;j<COL;j++)
            {
                if(strcmp(words[j] ,used[j]) == 0)
                {
                    count++;
                }
            }
            i++;
        }   
        printf("It's a pangram?\n");
        if (count >= NUM_OF_LETTERS)
        {
            printf("Yes!\n");
        }
        else
        {
            printf("No\n");
        }
        return 0;
    }

And I can't use pointers.


Solution

    1. Pangram :
      A pangram or holoalphabetic sentence is a sentence using every letter of a given alphabet at least once. Pangram - wiki

    2. Count only unique appearance of letters in the input words. Words can have both upper & lower case letters.

    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    
    #define MAX_INPUT_WORDS 10
    #define MAX_WORD_SIZE   50
    #define UNIQUE_LETTERS  26
    
    int main()
    {
        char* uniq_chars = "abcdefghijklmnopqrstuvwxyz";
        //create a look-up table for characters in an alphabet set
        char alpha_lt[256] = {0};
        for (int ai = 0; '\0' != uniq_chars[ai]; ++ai)
            alpha_lt[ (unsigned) uniq_chars[ai]] = 1;
    
        char words [MAX_INPUT_WORDS][MAX_WORD_SIZE];
    
        printf ("\nEnter up to 10 words, try to make a Pangram:\n");
        int uniq_count = 0; // tracks count of unique characters so far
        int wcount = 0;
        for (int wi = 0 ; wi < MAX_INPUT_WORDS; ++wi) {
            while (1 != scanf ("%49s", words[wi]));
            ++wcount;
            //count the unique characters from alphabet-set
            for (int ci = 0; '\0' != words[wi][ci]; ++ci) {
                //Pangram can have letter from different cases.
                int ichar = tolower (words[wi][ci]); // to homogenise upper/lower cases
                if (alpha_lt[ichar]) {    // uniq character not yet counted
                    ++uniq_count;
                    alpha_lt[ichar] = 0; // remove from LT; to skip
                    // counting during next occurance
                }
            }
            if (UNIQUE_LETTERS == uniq_count)
                break;
        }
    
        printf ("\nIs it a Pangram?\n");
        printf ((UNIQUE_LETTERS == uniq_count) ? "Yes!\n" : "No\n");
        for (int wi = 0; wi < wcount;)
            printf ("%s ", words[wi++]);
        printf ("\n");
    
        return 0;
    }
    
    1. Sample Pangrams for standard English:
    "Waltz, bad nymph, for quick jigs vex." (28 letters)  
    "Glib jocks quiz nymph to vex dwarf." (28 letters)  
    "Sphinx of black quartz, judge my vow." (29 letters)  
    "How vexingly quick daft zebras jump!" (30 letters)  
    "The five boxing wizards jump quickly." (31 letters)  
    "Jackdaws love my big sphinx of quartz." (31 letters)  
    "Pack my box with five dozen liquor jugs." (32 letters)  
    "The quick brown fox jumps over a lazy dog" (33 letters)  
    

    Invalid Pangrams for testing:

    ABCD EFGH IJK LMN OPQR STUVWXY Z  
    abcdef g h i jklmnopqrstuvwxyz