Home C String Functions strupr() C strupr() Function Definition In C, strupr() changes lowercase letters in a writable C-string to uppercase, in the same buffer. It is a common extension and is not part of ISO C. On Microsoft compilers the name is often _strupr().
You pass one writable string. It is required. The result is the same pointer. Prefer a portable loop with toupper when you need standard C.
Syntax Pass a writable char array. Start with this call.
Call What it does strupr(word)Turns lowercase letters in word into uppercase, in place.
Not ISO C. Never pass a string literal. Use a portable loop when you need standard C.
Library declarations char *strupr(char *str);
char *_strupr(char *str); Parameters Parameter Description str Required. A writable C-string. Do not pass a string literal.
Return Value Return Value Description str pointer The same pointer you passed in.
C Examples 1. Basic upper 2. Mixed characters 3. Normalize then compare Example 1 — Convert a Word to Uppercase Same idea as extension strupr, done with a portable toupper loop.
#include <ctype.h>
#include <stdio.h>
char *str_upr(char *s) {
char *start = s;
while (*s != '\0') {
*s = (char) toupper((unsigned char)*s);
s++;
}
return start;
}
int main(void) {
char buf[] = "Hello";
printf("before: %s\n", buf);
str_upr(buf);
printf("after: %s\n", buf);
return 0;
} before: Hello
after: HELLO How It Works Writable buffer. char buf[] can be modified in place.Cast to unsigned char. Required for safe use of toupper on every byte.Fold each letter. 'e', 'l', 'l', 'o' become uppercase.Stop at null. The terminator is not changed; length stays the same.Example 2 — Letters Only Change Digits and punctuation stay as they are—only alphabetic characters are folded.
#include <ctype.h>
#include <stdio.h>
char *str_upr(char *s) {
char *start = s;
while (*s != '\0') {
*s = (char) toupper((unsigned char)*s);
s++;
}
return start;
}
int main(void) {
char buf[] = "Code-123!";
str_upr(buf);
printf("%s\n", buf);
return 0;
} How It Works Scan the whole string. Every byte is passed through toupper.Letters fold. Code becomes CODE.Other bytes stay. '-', '1', '2', '3', '!' are unchanged.Useful for labels. You can normalize text without breaking codes or punctuation.Example 3 — Normalize Before Compare Uppercase both sides, then compare with strcmp for a simple case-insensitive check (ASCII).
#include <ctype.h>
#include <stdio.h>
#include <string.h>
char *str_upr(char *s) {
char *start = s;
while (*s != '\0') {
*s = (char) toupper((unsigned char)*s);
s++;
}
return start;
}
int main(void) {
char a[] = "Hello";
char b[] = "HELLO";
str_upr(a);
str_upr(b);
if (strcmp(a, b) == 0) {
printf("same (ignoring case)\n");
} else {
printf("different\n");
}
return 0;
} How It Works Normalize both strings. str_upr makes them uppercase.Compare with strcmp. Byte-for-byte equality after folding.Match. "HELLO" equals "HELLO" → printed message.Note. This mutates the originals; copy first if you need the old casing.Frequently Asked Questions What does strupr() do in C? strupr() converts lowercase letters in a writable C-string to uppercase, in place.
What is the parameter of strupr()? str is required. It must be a writable C-string, not a string literal.
What does strupr() return? The same str pointer you passed in.
Is strupr() portable? No. It is an extension. Use a portable toupper loop for ISO C.
Can I pass a string literal? No. String literals must not be modified.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful
Helpful Share Copy link Suggestion