strupr() converts letters in a string to uppercase on implementations that provide it, but it is not part of the ISO C standard library. Use toupper() for portable C.
strupr() as a compiler-specific extension.strupr(string); // non-standard extension
#include <ctype.h>
#include <stdio.h>
void to_uppercase(char text[]) {
for (size_t i = 0; text[i] != '\0'; i++) {
text[i] = (char)toupper((unsigned char)text[i]);
}
}
int main(void) {
char text[] = "plus2net.com 2026!";
to_uppercase(text);
printf("%s\n", text);
return 0;
}
Output
PLUS2NET.COM 2026!
#include <ctype.h>
#include <stdio.h>
void to_uppercase(char text[]) {
for (size_t i = 0; text[i] != '\0'; i++) {
text[i] = (char)toupper((unsigned char)text[i]);
}
}
int main(void) {
char words[][20] = {"apple", "banana", "c tutorial"};
for (size_t i = 0; i < 3; i++) {
to_uppercase(words[i]);
printf("%s\n", words[i]);
}
return 0;
}
The following variations restore distinct teaching purposes from the original page while using portable C instead of the non-standard strupr().
#include <ctype.h>
#include <stdio.h>
void to_uppercase(char text[]) {
for (size_t i = 0; text[i] != '\0'; i++) {
text[i] = (char)toupper((unsigned char)text[i]);
}
}
int main(void) {
char text[100];
printf("Enter a string: ");
if (fgets(text, sizeof text, stdin) == NULL) {
return 1;
}
to_uppercase(text);
printf("Uppercase: %s", text);
return 0;
}
#include <ctype.h>
#include <stdio.h>
int compare_ignore_case(const char *first, const char *second) {
while (*first != '\0' && *second != '\0') {
int a = tolower((unsigned char)*first);
int b = tolower((unsigned char)*second);
if (a != b) {
return a - b;
}
first++;
second++;
}
return (unsigned char)*first - (unsigned char)*second;
}
int main(void) {
const char first[] = "apple";
const char second[] = "Apple";
printf("%s\n",
compare_ignore_case(first, second) == 0
? "Strings are equal"
: "Strings are different");
return 0;
}
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.