C toupper
Normalize ASCII identifier bytes using the C character-conversion function in the active locale.
A simple example
toupper
- Start with "ab"
- Do this Convert to uppercase
- Result "AB"
Syntax
toupper
Run these examples in C
Save one example at a time as lesson.c. Use C17 and a Unix-style shell.
cc -std=c17 -Wall -Wextra lesson.c -lm -o lesson
./lessonNormalize a campus code
A school imports a short campus code from a form with inconsistent capitalization. Produce the standard spelling before joining the form record to the campus directory.
#include <ctype.h>
#include <stdio.h>
int main(void) {
char code[] = "bio";
for (size_t i = 0; code[i]; ++i)
code[i] = (char)toupper((unsigned char)code[i]);
puts(code);
return 0;
}
BIO
The input contains ASCII. Converting each byte to unsigned char makes it valid for the character-classification API.
Normalize an airport tag
Two terminals can enter the same short label with different capitalization or padding. Normalize the incoming spelling before lookup so the stored identifiers can follow a consistent convention.
#include <ctype.h>
#include <stdio.h>
int main(void) {
char code[] = "maa-2";
for (size_t i = 0; code[i]; ++i)
code[i] = (char)toupper((unsigned char)code[i]);
puts(code);
return 0;
}
MAA-2
The input contains ASCII. Converting each byte to unsigned char makes it valid for the character-classification API.
Print a workshop badge
A student types a lower-case room assignment. Convert the letter part to uppercase for the printed label. Digits and the separator retain their spelling.
What to watch for
For UTF-8 human names choose a Unicode-aware casing library. These examples run with the default C locale.