toupper()

Updated: April 19, 2023

Convert a character to uppercase

Synopsis:

#include <ctype.h>

int toupper( int c );

Arguments:

c
The character that you want to convert. This must be representable as an unsigned char or be EOF; the behavior for other values is undefined. Because this argument is interpreted as an int, to avoid sign extension on character values greater than 0x7F, you must cast the argument to the unsigned data type; otherwise, the function will behave unpredictably.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The toupper() function converts c to a uppercase letter, if c represents a lowercase letter.

Returns:

The corresponding uppercase letter when the argument is a lowercase letter; otherwise, the original character is returned. If the original character can't be represented as an unsigned char and isn't EOF, the behavior is undefined.

Examples:

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

char chars[] = {
    'a',
    '5',
    '$',
    'z'
};

#define SIZE sizeof( chars ) / sizeof( char )

int main( void )
  {
    int   i;

    for( i = 0; i < SIZE; i++ ) {
    printf( "%c ", toupper( (unsigned)chars[ i ] ) );
    }
    printf( "\n" );
    return EXIT_SUCCESS;
  }

produces the output:

A 5 $ Z

Classification:

ANSI, POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes