C Program to Check a Pangram String
C Program to Check a Pangram String
A school text exercise needs to english pangram while preserving the buffer’s valid characters and final terminator.
An English pangram contains every basic English alphabet letter at least once, ignoring case under the stated basic-text policy.
Before this exercise, review strings and their terminator and array bounds. The worked program below applies those ideas to this specific problem.
Explain
Explain why english pangram uses this sequence of operations.
Trace
Trace the sample values and predict the printed result.
Apply
Check River School, which lacks many of the required letters.
English Pangram: follow the data
Given data
A school text exercise needs to english pangram while preserving the buffer’s valid characters and final terminator.
Rule
An English pangram contains every basic English alphabet letter at least once, ignoring case under the stated basic-text policy.
Observed result
Pangram
Understand the operation
A seen flag tracks each explicitly listed alphabet character. Repeated letters do not increase coverage, and spaces do not require flags.
A C string ends at its first null character. Read only within its accessible storage and reserve a position for that terminator when producing a changed string. These examples use basic text bytes, not a Unicode grapheme-processing library.
Read the complete C program
The input values are written into this complete C17 example so the calculation can be reproduced without an unavailable service. Change the named data, rebuild and compare the actual output with your prediction.
C17 · complete program
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
const char text[] = "The quick brown fox jumps over the lazy dog", alphabet[] = "abcdefghijklmnopqrstuvwxyz";
int seen[26] = {0};
for (size_t i = 0; text[i] != '\0'; i++) {
int lower = tolower((unsigned char)text[i]);
for (int letter = 0; letter < 26; letter++) if (lower == alphabet[letter]) seen[letter] = 1;
}
int all = 1;
for (int letter = 0; letter < 26; letter++) if (!seen[letter]) all = 0;
puts(all ? "Pangram" : "Not pangram");
return 0;
}
Expected output
Pangram
Run in C compiler →Follow the values through the code
C17 · code used in this explanation
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
const char text[] = "The quick brown fox jumps over the lazy dog", alphabet[] = "abcdefghijklmnopqrstuvwxyz";
int seen[26] = {0};
for (size_t i = 0; text[i] != '\0'; i++) {
int lower = tolower((unsigned char)text[i]);
for (int letter = 0; letter < 26; letter++) if (lower == alphabet[letter]) seen[letter] = 1;
}
int all = 1;
for (int letter = 0; letter < 26; letter++) if (!seen[letter]) all = 0;
puts(all ? "Pangram" : "Not pangram");
return 0;
}
The sample sentence sets all twenty-six flags; the final scan finds no missing letter.
Compare the printed answer with the original text and the stated ordering or filtering rule. The presence of a terminator makes %s usable; it does not by itself make every earlier write fit.
Follow the worked calculation
Start with the sample
The sample sentence sets all twenty-six flags; the final scan finds no missing letter.
Apply the rule
Compare the printed answer with the original text and the stated ordering or filtering rule. The presence of a terminator makes %s usable; it does not by itself make every earlier write fit.
Check the result
Pangram
Pangram
Try a small variation
C17 · code used in this explanation
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
const char text[] = "The quick brown fox jumps over the lazy dog", alphabet[] = "abcdefghijklmnopqrstuvwxyz";
int seen[26] = {0};
for (size_t i = 0; text[i] != '\0'; i++) {
int lower = tolower((unsigned char)text[i]);
for (int letter = 0; letter < 26; letter++) if (lower == alphabet[letter]) seen[letter] = 1;
}
int all = 1;
for (int letter = 0; letter < 26; letter++) if (!seen[letter]) all = 0;
puts(all ? "Pangram" : "Not pangram");
return 0;
}
Check River School, which lacks many of the required letters.
Worked answer
The complete worked answer applies the same explicitly bounded operation to a small variation. Read its stored bytes and terminator separately from the visible output.
C17 · complete program
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
const char text[] = "River School", alphabet[] = "abcdefghijklmnopqrstuvwxyz";
int seen[26] = {0};
for (size_t i = 0; text[i] != '\0'; i++) {
int lower = tolower((unsigned char)text[i]);
for (int letter = 0; letter < 26; letter++) if (lower == alphabet[letter]) seen[letter] = 1;
}
int all = 1;
for (int letter = 0; letter < 26; letter++) if (!seen[letter]) all = 0;
puts(all ? "Pangram" : "Not pangram");
return 0;
}
Expected output
Not pangram
Run in C compiler →Recognize the important boundaries
This English alphabet definition is not a universal pangram definition for every language. It avoids assuming alphabet characters have contiguous numeric codes.
An untrusted input string needs a verified buffer bound and a valid terminator. strlen is not a safe way to prove arbitrary raw storage has a terminator.
Check your understanding
Choose the answer, then compare the reasoning for every option.
Use the idea independently
An English pangram contains every basic English alphabet letter at least once, ignoring case under the stated basic-text policy.
Continue with character-array storage.
Continue with bounded line reading.
Language reference: WG14 C11 committee draft. These examples use the C17-compatible subset of the explained language features.
Reaching the recap and completing the quizzes are separate milestones.