C Program TO REVERSE THE GIVEN STRING

C Program TO REVERSE THE GIVEN STRING | reverse the string in C | Reverse Sentence in C Language




#include
#include
void strev(char str1[50], char str2[50]);
void main()
{
          char str1[50], str2[50];
          clrscr();
          printf("\n\n\t ENTER A STRING...: ");
          gets(str1);
          strev(str1,str2);
          printf("\n\t THE REVERSED STRING IS...: ");
          puts(str2);
          getch();
}
void strev(char str1[50], char str2[50])
{
          int i = 0, len = 0, r = 0;
          while(str1[len]!='\0')
                 len++;
          for(i=len-1; i>=0; i--)
          {
                 str2[r] = str1[i];
                 r++;
          }
          str2[r] = '\0';
}


No comments:

Post a Comment