#include<stdio.h>
int main(void)
{
char str1[10]="Versace";
int length(char *p);
char* reverse(char *p);
printf("Length of the array is %d\n",length("Versace"));
printf("Reversed string %s",reverse("Versace"));
}
int length(char*p)
{
int i;
for(i=0;*(p+i)!='\0';i++);
return i;
}
char* reverse(char *p)
{
int i,l;
char temp;
for(l=0;*(p+l)!='\0';l++);
for (i=0;i<(l/2);i++)
{
temp=*(p+i);
*(p+i)=*(p+l-1-i);
*(p+l-1-i)=temp;
}
return(p);
}
I have written a code to find the length of a string and to reverse a string.For this purpose I've made 2 functions reverse and length. But, why does this code show error? The code works fine if I use str1 as parameter in reverse function in the second printf.