20120113

Program in Cpp to learn to reverse a strings in Cpp

//========================
//Program in Cpp to learn to reverse a strings in Cpp, strrevcpp2.cpp
//========================
#include<iostream>
using namespace std;
#include<string.h>
int main()
{
char orgstr[]="manoj";
cout<<"orginal string is:\n"<<orgstr;
char revstr[50];
char *p1,*p2;
p1=orgstr+strlen(orgstr)-1;
p2=revstr;
while(p1>=orgstr)
*p2++=*p1--;
*p2='\0';
cout<<"\n reversed string is: \n"<<revstr;
return 0;
}


Previous                             Home                               Next

No comments:

Post a Comment