Wednesday, July 20, 2011

Program to reverse the string {using Pointer}

/*Serial No.55     [swami27.cpp]*/

#include<stdio.h>
#include<conio.h>
void reverse(char *);
void main()
{
clrscr();
  char st[10];
  gets(st);
  printf("reverse=");
  reverse(st);
  printf("\noriginal data=%s",st);
  getch();
}
void reverse(char *s)
{
  char c;
  if (*s==NULL)
  {
     return;
  }
  c=*s;
  s++;
  reverse(s);
  printf("%c",c);
}

No comments:

Post a Comment

If you have any doubt, feel free to ask...