String Reverse Using Pointer


#include <iostream.h>
#include <conio.h>
#include <string.h>

void StrRev(char *p)
{
   char *q;
   int len=strlen(p),i=0;
   char c[10];
   i=0;
   q=&p[len-1];
   while(i<len)
   {
       c[i]=*q;
       q--;
       i++;
   }
   c[i]='\0';
   cout<<c;
}

void main ()
{
   char c[]="hello";
clrscr();
   StrRev(c);
getch();
}

No comments

Post your comments

Powered by Blogger.