1
I tried to do a function in order to invert a string but the program always returns (null).
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char reverse(char string[])
{
int length, i;
length = strlen(string);
char reverse_string[length];
for(i=0; i<length; i++)
{
reverse_string[i] = string[(length - i) - 1];
}
return reverse_string;
}
int main()
{
char string[50];
gets(string);
printf("%s", reverse(string));
return 0;
}
I thought I might be putting the character ' 0' in the first position of reverse_string, but I added the "-1" in the operation and even then the program always returns (null). If anyone knows what’s going on and can give a hint, I’d appreciate it!
Ricardo, your answer does not help to solve the question specific problem and yet posted a code in another language, try to give a more direct answer to the question problem
– Ricardo Pontual