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.

Categoryctype.h character classes
KindLibrary function
Header<ctype.h>
C standardC89 / C90

📝 Syntax

int toupper(int c);

⚙️ Parameters

c RequiredThe 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 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏