using pointers concept reverse a given string

Q. using pointers concept reverse a given string
ANS. #include 
 
int main()
{
    char str[1000], *ptr;
    int i, len;
    printf("Enter a string: ");
    gets(str);
    ptr = str;
    for(i=0;i<1000;i++){
        if(*ptr == '\0')  break;
        ptr++;
    }
    len = i;
    ptr--;
    printf("Reversed String: ");
    for(i=len; i>0; i--){
        printf("%c",*ptr--);
    }
    return 0;
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.