Sunday, 26 May 2013

0 A C - PROGRAM TO REVERSE A GIVEN STRING.

REVERSE A GIVEN STRING
This program reverses a string entered by the user. For example if a user enters a string "reverse me" then on reversing the string will be "em esrever".

 THE PROGRAM IS :

#include<stdio.h>
#include<conio.h>
void reverse(char[]);
char str[100],r[100],revstr[100];
int i,j,k;
void main()
{
    printf("Enter the string \n");
    gets(str);
    reverse(str);
}
    void reverse(char r[100])
    {
        k=0;
        for(i=0;r[i]!='\0';i++)
        {
            k++;
        }
        j=0;
        for(i=k-1;i>=0;i--)
        {
            revstr[j]=r[i];
            j++;
        }
        printf("The original string is \n");
        puts(str);
        printf("The reversed string is \n");
        for(i=0;i<k;i++)
        {
            printf("%c",revstr[i]);
        }
        printf("\n");
        getch();
    }



Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software) 
Or else you can try this demo file and use it ... 
Click HERE to download this file. 
(Press ctrl+z and hit Enter to end the program).. 
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program... 



IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

No comments:

Post a Comment