Check string is pangram or not in C

How to check if all letters of the alphabet are in an array with C (check if it is a pangram)

int main()
{
    char str[] = "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBN";

    int freq[256];
    int i;

    for ( i = 0; i < 256; i ++) // clear frequency array
    {
        freq[i] = 0;
    }

    for (i = 0; str[i] != '\0'; i++) // parse input string
    {
        freq[str[i]]++;
    }

    for ( i = 0; i < 256; i ++)
    {
        if (freq[i]==0 && isalpha(i)) // find out which leters weren't typed
        {
            printf("%c letter wasn't typed!\n", (char)i);
        }
    }

    return 0;
}

Share this post


Comments (0)

  • Be first to comment

Leave a comment

or to Comment

Contact Us

  • Address: # 650 Narsi Village Sector 32 Urban Estate Karnal-132001 Haryana, India

  • Phone:(+91) 97289-77666   Email: codethor84@gmail.com


Follow Us