Friday, 12 August 2016

Reversing the string without using Library function

Reversing the string without using Library function


#include<stdio.h>
#include<string.h>
void main()
{
                char str[20], rev[20], temp;
                int i=0, j;
                printf("\nEnter the string: ");
                gets(str);

                j = strlen(str) - 1;
                while(i<j)
                {
                                temp = str[j];
                                str[j] = str[i];
                                str[i] = temp;
                                i++;
                                j--;
                }

                printf("\nReversed string: ");
                puts(str);
}

Output:
Enter the string:   newspaper
Reversed string:   repapswen

Also check,
https://tejaswinihbhat.blogspot.in/2016/08/strrev-reversing-string-using-library.html

No comments:

Post a Comment