toupper()関数やtolower()関数について
Posted: 2012年8月15日(水) 03:47
いずれも戻り値、引数の指定がint型なのにchar型の配列の要素を渡すことができるのは何故なのでしょうか?
ご教授お願いします
ご教授お願いします
#include <stdio.h>
#include <ctype.h>
int main()
{
char* p = "abc";
printf_s("%s\n",toupper(p));//ここでchar*からintへの変換ができません。
}
厳密なことを言うと、toupper 関数の int型の引数に char型配列の要素を渡すことは規格違反です。やまだ さんが書きました:いずれも戻り値、引数の指定がint型なのにchar型の配列の要素を渡すことができるのは何故なのでしょうか?
7.4 Character handling <ctype.h>
The header <ctype.h> declares several functions useful for classifying and mapping
characters.166) In all cases the argument is an int, the value of which shall be
representable as an unsigned char or shall equal the value of the macro EOF. If the
argument has any other value, the behavior is undefined.