The strupr() function converts every lowercase letter in a C string to uppercase in place. It is a convenient extension on some compilers, but beginners should also learn the portable toupper() loop that works everywhere.
01
Uppercase
In place.
02
char*
Same buf.
03
Not ISO C
Extension.
04
toupper
Portable.
05
Writable
char[].
06
vs strlwr
Lowercase.
Fundamentals
Definition and Usage
strupr walks a modifiable null-terminated string and replaces each lowercase letter with its uppercase equivalent. Digits, spaces, and punctuation stay as they are. The function returns the same pointer you passed in because the transformation happens inside the original buffer.
For example, "Hello, C!" becomes "HELLO, C!"—only the letters H, e, l, l, and o change case.
⚠️
Portability Warning
strupr() is not part of ISO standard C. GCC and Clang on Linux typically do not provide it. Use a small toupper loop for portable projects, or _strupr() when targeting MSVC with appropriate #ifdef guards.
Foundation
📝 Syntax
Common extension declaration (availability varies by compiler):
C
char *strupr(char *str);
Parameters
str — pointer to a modifiable, null-terminated string to convert.
Return Value
Pointer to str after in-place conversion (same address as the input).
Headers
strupr / _strupr — <string.h> on toolchains that provide the extension.
Portable alternative — <ctype.h> for toupper().
Cheat Sheet
⚡ Quick Reference
Before
After strupr / toupper loop
"Hello, C!"
"HELLO, C!"
"abc123"
"ABC123"
"ALREADY UPPER"
"ALREADY UPPER" (unchanged)
writable buffer
required (not string literal)
portable
toupper((unsigned char)c) per byte
Extension
strupr(buf);
If available
MSVC
_strupr(buf);
Windows
Portable
str_to_upper(buf);
toupper loop
Compare only
strcasecmp(a, b)
No modify
Hands-On
Examples Gallery
Examples use the portable toupper helper so they compile on Linux, macOS, and Windows. Where _strupr exists, it behaves the same way in place.
📚 Getting Started
Uppercase every letter in a writable char array.
Example 1 — Convert to Uppercase (Portable)
Turn "Hello, C!" into uppercase, matching the reference tutorial.
Uppercasing is useful for consistent display formatting. For locale-aware text (accents, Unicode), ASCII toupper is not enough—but it covers basic English tutorials.
Example 4 — toupper() on One Character
See what changes and what stays the same.
C
#include <stdio.h>
#include <ctype.h>
int main(void) {
char letters[] = "a B c";
for (int i = 0; letters[i]; i++) {
unsigned char c = (unsigned char)letters[i];
printf("'%c' -> '%c' ", letters[i], (char)toupper(c));
}
printf("\n");
return 0;
}
toupper only affects lowercase letters in the current C locale. Spaces and already-uppercase letters pass through unchanged—that is exactly what strupr does across a whole string.
Example 5 — Using _strupr() on Windows
When your toolchain provides the extension, call it directly on a writable buffer.
C
/* Windows / MSVC example */
#include <stdio.h>
#include <string.h>
int main(void) {
char buf[] = "Hello, C!";
#if defined(_MSC_VER)
_strupr(buf);
printf("Uppercase: %s\n", buf);
#else
printf("_strupr is not available on this platform.\n");
printf("Use the portable toupper loop instead.\n");
#endif
return 0;
}
📤 Output (MSVC):
Uppercase: HELLO, C!
How It Works
_strupr modifies buf in place and returns the same pointer. Guard with preprocessor checks so Linux CI builds still compile.
Applications
🚀 Common Use Cases
Display formatting — print headings or labels in uppercase.
Normalized keys — store identifiers in one case for lookup tables.
Teaching case folding — connect character functions to whole-string transforms.
Legacy code — read programs that call strupr on Windows toolchains.
🧠 How strupr() Works
1
Start at str[0]
Walk until '\0'.
Scan
2
Apply toupper
Replace lowercase ASCII letters in place.
Fold
3
Leave others alone
Digits, space, punctuation unchanged.
Skip
=
📝
char* str
Same buffer, now uppercase letters.
Important
📝 Notes
Not part of ISO C—treat as a vendor extension unless your docs guarantee it.
Modifies the buffer in place; requires a writable char[], not a literal.
Uses the current C locale rules inside toupper—ASCII-centric in typical tutorials.
For case-insensitive comparison without mutation, prefer strcasecmp() or _stricmp().
Pair conceptually with strlwr() for the opposite transformation.
Performance
⚡ Optimization
Uppercasing a string is O(n) in the length of the text. For short identifiers the cost is negligible. Avoid repeated uppercasing of the same string in a hot loop—fold once and reuse the result.
Wrap Up
Conclusion
strupr() uppercases a string in one call on compilers that provide it. For portable code, implement a tiny toupper loop and use _strupr only behind platform guards.
Use a portable toupper loop for cross-platform code
Pass writable char buffer[] arrays
Copy with strcpy when the original must stay unchanged
Cast bytes to unsigned char before toupper
Wrap _strupr in #if defined(_MSC_VER)
❌ Don’t
Assume strupr exists on every compiler
Call it on string literals
Expect Unicode or UTF-8 full case mapping from ASCII toupper
Uppercase both strings just to compare once—use strcasecmp
Forget that the original text is destroyed in place
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about strupr()
Use these points when folding strings to uppercase in C.
5
Core concepts
📝01
In place
Same buf.
Basics
⚠️02
Extension
Not ISO.
Portability
🔢03
toupper
Portable.
Pattern
📈04
Writable
char[].
Safety
💬05
vs strlwr
Lowercase.
Compare
❓ Frequently Asked Questions
strupr() converts every lowercase letter in a string to uppercase, modifying the string in place. It returns a pointer to the same buffer. Non-letter characters are left unchanged.
No. strupr() is a compiler-specific extension (common on older Microsoft and Borland toolchains). ISO C does not define it. For portable code, write a loop with toupper() from <ctype.h>.
toupper() converts one character. strupr() (where available) converts an entire null-terminated string in place. A portable helper loops over each byte and applies toupper().
No. String literals are read-only. strupr() modifies memory, so pass a writable char array or heap buffer.
Microsoft documents _strupr() in <string.h>. Some environments also expose strupr as an alias. Check your compiler documentation.
strupr() folds letters to uppercase; strlwr() folds them to lowercase. Both are non-standard extensions that mutate the buffer in place.
Did you know?
Standard C never added strupr or strlwr, but C++ offers std::toupper in <cctype> and higher-level case APIs in later standards. In pure C, a five-line toupper loop is the portable replacement students should memorize.