panagram in c

Writing a Panagram in C

To write a panagram in C, we need to create a program that checks if a given string contains all the letters of the alphabet. Here's an example of how you can write a panagram program in C:

#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>

bool isPanagram(const char* str) {
    int alphabet[26] = {0}; // Initialize an array to keep track of letter occurrences

    while (*str) {
        if (isalpha(*str)) {
            alphabet[tolower(*str) - 'a']++; // Increment the count for the corresponding letter
        }
        str++;
    }

    for (int i = 0; i < 26; i++) {
        if (alphabet[i] == 0) {
            return false; // If any letter is missing, return false
        }
    }

    return true; // All letters are present
}

int main() {
    const char* sentence = "The quick brown fox jumps over the lazy dog";
    bool isPanagramResult = isPanagram(sentence);

    if (isPanagramResult) {
        printf("The sentence is a panagram.\n");
    } else {
        printf("The sentence is not a panagram.\n");
    }

    return 0;
}

Explanation of the code: 1. The isPanagram function takes a string as input and returns a boolean value indicating whether the string is a panagram or not. 2. Inside the isPanagram function, an array alphabet of size 26 is initialized to keep track of the occurrences of each letter in the alphabet. 3. The function iterates over each character in the input string using a while loop. 4. If the character is an alphabet letter, its count in the alphabet array is incremented. The tolower function is used to convert the character to lowercase before indexing the alphabet array. 5. After iterating over all the characters, a for loop checks if any letter count in the alphabet array is zero. If any letter is missing, the function returns false. 6. If all letters are present, the function returns true. 7. In the main function, a sample sentence is declared and passed to the isPanagram function. 8. The result is printed based on the return value of the isPanagram function.

Note: This code assumes that the input string contains only ASCII characters and does not handle non-ASCII characters.

[[SOURCE 5]]