Hi. Can someone help me with the following code? I know something is wrong but not what it is.
gcc gives me these errors>
reverse_str.c: In function `reverse_string':
reverse_str.c:31: warning: return makes integer from pointer without a cast
reverse_str.c:31: warning: function returns address of local variable
--------------------------------------------------------
#include <stdio.h>
char reverse_string(char *str);
int main(void)
{
char *string = "This will print backwards";
printf("%s\n", reverse_string(string));
return 0;
}
char reverse_string(char *str)
{
char str2[40];
int x = 0;
int y = 0;
while (str[x] != '\0')
x++;
while ( x >= 0)
str2[y++] = str[x--];
/* append NULL character to string */
str2[y] = '\0';
return str2;
}
thanks