toupper() Convert a letter to uppercase
toupper() Convert a letter to uppercase
toupper() maps lowercase to uppercase in the current locale, leaving others unchanged. Pass EOF or unsigned char; it returns int and cannot map UTF-8.
| Category | ctype.h character classes |
|---|---|
| Kind | Library function |
| Header | <ctype.h> |
| C standard | C89 / C90 |
📝 Syntax
int toupper(int c);
⚙️ Parameters
| c Required | The character to convert, represented as an unsigned char value or EOF. |
|---|
Returns: Returns the uppercase equivalent when one exists, or c unchanged otherwise.
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
C LANGUAGE 89
⚠️ Warning The argument must be an unsigned char value or EOF. Do not pass a plain char value that may be negative.
💡 Tip toupper() returns the converted int and does not modify the original string; the example passes its result directly to putchar().
🏷️ Related ctype.h functions
📚 Related Tutorials
❓ FAQ
QDoes toupper modify the original string?
ANo. It returns a converted character value only. To modify an array, explicitly assign the result back to the desired element.
QWhat does toupper do with digits or punctuation?
AThese characters have no uppercase form, so they are returned unchanged. Conversion is locale-sensitive, but digits and ordinary punctuation remain unchanged in the C locale.
QWhy is char often converted to unsigned char before calling toupper?
AThe valid argument domain for toupper consists only of EOF and values representable as unsigned char. On platforms where char is signed, non-basic characters may produce negative values, and passing them directly causes undefined behavior. Converting first preserves the original byte value; then write the returned int back to the target character.