20120113

Program in C to reverse a string

Program in C to reverse a string, revstr99.cpp

#include<iostream>
using namespace std;
int main()
{
char orgstr[50];
char revstr[50];
cout<<"Enter a String: "<<endl;
cin>>orgstr;
char *p1,*p2;
p1=orgstr+ strlen(orgstr)-1;
p2=revstr;
while(p1>p2)
        {
        *p2++ = *p1--;
        }
*p2='\0';
cout<<"Reversed String is:"<<revstr;
cout<<endl;
return 0;
}


Previous                             Home                               Next

No comments:

Post a Comment