Write a fucntion that will reverse a string.

Q

Write a fucntion that will reverse a string.

✍: Guest

A
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);

}

2012-04-11, 2495👍, 0💬