0

why does one give me an int and the other doesn't?:

    toupper(member_names[2]);

and:

    member_names[2] = toupper(member_names[2]);
Code971
  • 325
  • 1
  • 2
  • 4

2 Answers2

1

The toupper function does not modify its argument. So this call:

toupper(member_names[2]);

returns a value that you ignore.

The other version is taking the value from the toupper function and assigning it to member_names[2] thus modifying the previous value.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
0

toupper takes a character (encoded into an int for mostly-historical reasons) and returns the upper-case equivalent of that character.

Therefore, your first version doesn't really accomplish anything. Your second converts member_names[2] to its upper-case equivalent.

Also note that (in most implementations) a char can have a negative value (e.g., accented characters in ISO 8859-*). Passing a negative value to toupper can/will lead to (serious) problems--unless member_names is an array of unsigned char, you normally want to case to unsigned char before passing to toupper:

member_names[2] = toupper(static_cast<unsigned char>(member_names[2]));
Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111