Write a fucntion that will reverse a string.
C++ programming on UNIX, C++ Networking,C++ Algorithm Questions and Answers
(Continued from previous question...)
Write a fucntion that will reverse a string.
char *strrev(char *s)
{
int i = 0, len = strlen(s);
char *str;
if ((str = (char *)malloc(len+1)) == NULL)
/*cannot allocate memory */
err_num = 2;
return (str);
}
while(len)
str[i++]=s[–len];
str[i] = NULL;
return (str);
}
(Continued on next question...)
Other Interview Questions
|