toupper Function

Convert a character to an uppercase alphabetical character.

Include

<ctype.h>

Prototype

int toupper (int c);

Argument

c
The character to convert to uppercase.

Return Value

Returns the corresponding uppercase alphabetical character if the argument, c, was originally lowercase; otherwise, returns the original character.

Remarks

Only lowercase alphabetical characters may be converted to uppercase.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <ctype.h>
#include <stdio.h>

int main(void)
{
  int ch;

  ch = 'b';
  printf("b changes to uppercase %c\n",
          toupper(ch));

  ch = 'B';
  printf("B remains uppercase %c\n",
          toupper(ch));

  ch = '@';
  printf("@ has no uppercase, ");
  printf("so %c is returned\n", toupper(ch));
}

Example Output

b changes to uppercase B
B remains uppercase B
@ has no uppercase, so @ is returned