-
Simple pointer question
Some code I'm reading contains this function:
Code:
char* strupr(char* str)
{
char *s = str;
while (*s)
{
*s = toupper(*s);
s += 1;
}
return (str);
}
...and I was just wondering why the need for 's' at all, when you could just perform the same operation on 'str'?
-
If these operations were performed directly on str, it is true that the string used as the argument in the calling function would be converted to uppercase, but the char * that the function returns would point to the null char at the end of the string instead of pointing to the beginning of the string.
-
D'oh, of course....:rolleyes: