Write a C program to accept the reverse of a string using pointers.

#include<stdio.h>
#include<conio.h>
main()
{
    char str[20],rev[20];
    char *st,*rv,*start;
    clrscr();
    printf("\nEnter a string");
    gets(str);
    st=str;
    rv=rev;
    start=st;
    while(*st!='\0')
    st ++;
    rv --;
    while(st>=start)
    {
      *rv=*st;
      st--;
      rv++;
    }
    *rv='\0';
    printf("\nThe original string is %s",str);
    printf("\nThe reverse string is %s",rev);
    getch();
    return;
}

No comments:

Post a Comment