getting trouble with this program.
trying to return a reverse string to main but it doesn't work.
when I put the function into main it works.
I think I'm not using the correct way dealing with pointers.
What am I doing wrong?
Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
char * rev(char * word);
int main()
{
char word1[100];
char rev1[100];
printf("Enter a word");
scanf("\n%s",word1);
strcpy(rev1,rev(word1));
printf("\nThe reverse order of this word is: %s",rev1);
return 0;
}
char * rev(char * word)
{
int len=strlen(word);
char reverse[len];
int j=0;
for(int i=len-1;i>=0;i--)
{
reverse[i]=word[j];
++j;
}
reverse[len]='\0';
return reverse;
}