Sunday, 20 March 2016

C Program For Reverse A String Using Pointer

#include<stdio.h>
int main()
{
    char str[50];
    char revStr[50];

    char *strPtr = str;
    char *revPtr = revStr;

    int len = -1;

    printf("\nEnter any string :\n\n");
    scanf("%s",str);
 
    while(*strPtr)
{
     strPtr++;
     len++;
    }
 
    while (len >= 0)
{
     strPtr--;
     *revPtr = *strPtr;
     revPtr++;
     --len;
    }
 
    *revPtr='\0';
    printf("\nReverse of string is : \n%s",revStr);
    return 0;
}

Output:-


No comments:
Write comments

Recommended Posts × +