Possible Duplicate:
Im trying to make this code recursive but for some reason it doesnt work
Im trying to write program using RECURSION to change multiple spaces to one space can anyone help ? example "a_______b" changes to "a_b" it is a task that im trying to do for a long time ! can anyone help ?
here i tried this but i think the design doesnt work for recursion
void text_r(char *str)
{
char *dst = str;
if(*str=='\0')return ;
*dst++ = *str;
if (isspace(*str)) {
do ++str; while (isspace(*str));
--str;
}
return text_r(str++);
}
i wrote the code without recursion but i have problem in converting it
void compress_spaces(char *str) { char *dst = str;
for (; *str; ++str) {
*dst++ = *str;
if (isspace(*str)) {
do ++str; while (isspace(*str));
--str;
}
}
*dst = 0;
}