Meldreth: Being pedantic, but:
You declare and define a funciton called "sdup", then call strdup() which is a non-standard but common library function.
Also, I very much prefer a variant where you pass in the receiving string, e.g.
Code:
char *supper(const char *in, char *out, int maxlen)
{
char *s = out;
while(*in && s - out < maxlen-1)
{
*s++ = toupper(*in);
in++;
}
*s = 0;
return out;
}
The maxlen parameter is there to prevent buffer overflows.
The advantage here is that the user has the choice of using a dynamically, stack or static allocation for the receiving variable. Returning the original is useful if you want to do stuff like:
Code:
char something[100];
char temp[4];
const char *abc = "abc";
strcpy(something, abc);
strcat(something, supper(abc, temp, sizeof(temp)));
--
Mats