Saturday, August 9, 2014

Program to reverse a string

Program to reverse a string. You'll need to work with pointers in this program. If you need help, comment below

#include<stdio.h> #include<string.h> main() { char *ptr; char string[50],t; int i,j,l; ptr=string; printf("\nEnter the string"); gets(string); l=strlen(string); for(i=0,j=l-1;i<=(l-1)/2;i++,j--) { t= *(ptr+i); *(ptr+i)= *(ptr+j); *(ptr+j)=t; } printf("Reverse string is %s\n",string); }

No comments:

Post a Comment