Pages

Saturday, 20 June 2015

User defined string function to reverse

User defined string function to reverse of any given string

Coding:
#include<stdio.h>

void mystrrev(char *a)
{
int i,j,l;
char t;
for(i=0;a[i]!='\0';i++);
l=i;
i=i-1;
for(j=0;j<l/2;j++,i--)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}

int main()
{
char b[30];
printf("Please enter the string:");
gets(b);
mystrrev(b);
printf("After reverse:%s",b);
return 0;
}

Output:
Please enter the string:reverse
After reverse:esrever