L
Liviu
Say i have a function:
char *rmtrail(char *str)
{
if (str)
{
int i;
for (i = strlen(str) - 1; i >= 0 && isspace(str); --i)
;
str[++i] = '\0';
}
return str;
}
that removes trailing spaces from a string. The result of this
function will be different, if I change the return type from char* to
void and remove 'return str' ? I mean, in the caller function i call
rmtrail, passing a pointer to string. Even though in rmtrail, i
received a copy of the pointer to my string, the modified string will
be the same, so where's the need to return 'str' from rmtrail
function ? This function was not coded by me, but it works fine.
I just want to know if there is any difference...
char *rmtrail(char *str)
{
if (str)
{
int i;
for (i = strlen(str) - 1; i >= 0 && isspace(str); --i)
;
str[++i] = '\0';
}
return str;
}
that removes trailing spaces from a string. The result of this
function will be different, if I change the return type from char* to
void and remove 'return str' ? I mean, in the caller function i call
rmtrail, passing a pointer to string. Even though in rmtrail, i
received a copy of the pointer to my string, the modified string will
be the same, so where's the need to return 'str' from rmtrail
function ? This function was not coded by me, but it works fine.
I just want to know if there is any difference...