Write a c program to reverse a string using pointers

Write a c program to reverse a string using pointers. The performance is “olleh” if the string is “hello.” .This method needs two pointers, one pointing to the beginning of the string and the other pointing to the end of the string

#include <stdio.h>
int main()
{
char str[100];
char rev[100];
char *sptr = str; 
char *rptr = rev; 
int i = -1;
printf("\n\nEnter the string");
scanf("%s", str);
while(*sptr)
{
sptr++;
i++; 
}
while(i >= 0)
{
sptr--; 
*rptr = *sptr; 
rptr++; 
i--; 
}
*rptr = '\0'; 
rptr = rev; 
while(*rptr)
{
*sptr = *rptr;
sptr++;
rptr++;
}
printf("\n\nReverse of the string is: %s ", str);
return 0;
}

 

Output:

Enter the string inlarn

Reverse of the string is: nralni