Hàm toupper convert kí tự in thường thành in hoa

int toupper( int c );

Parameter:

c : kí tự đầu vào để convert thành kí tự in hoa

Remark:

Hàm toupper ( ) kiểm tra tham số c và convert kí tự c thành kí tự in hoa. Nếu c là kí tự in thường, hàm sẽ trả về kí tự in hoa. Để đảm bảo hàm toupper( ) trả về kết quả mong muốn, chúng ta cần dùng hàm islower( ) để kiểm tra kí tự cần convert là kí tự in thường.

Ví dụ:

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

void main()
{
    int c = 97; // character 'a'
    if(islower(c))
    {
        printf("\n%c is lowercase character", c);
        printf("\n%c is converted into uppercase: %c",c, toupper(c));
    }
    else
    {
        printf("\n%c is not lowercase character", c);
    }
    getch();
}

Kết quả:

Hàm toupper() convert kí tự in thương thành in hoa

Be the first to comment

Leave a Reply