c++ - why does these toupper work different when utilized like this? -
why 1 give me int , other doesn't?:
toupper(member_names[2]); and:
member_names[2] = toupper(member_names[2]);
toupper takes character (encoded int mostly-historical reasons) , returns upper-case equivalent of character.
therefore, first version doesn't accomplish anything. second converts member_names[2] upper-case equivalent.
also note (in implementations) char can have negative value (e.g., accented characters in iso 8859-*). passing negative value toupper can/will lead (serious) problems--unless member_names array of unsigned char, want case unsigned char before passing toupper:
member_names[2] = toupper(static_cast<unsigned char>(member_names[2]));
Comments
Post a Comment