C Program to Reverse String Without Using Library Function

C Program to Reverse String Without Using Library Function:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



#include<stdio.h>
#include<string.h>
main()
{
   char str[100],temp;
   int i,j=0;

   printf("Enter the string :");
   gets(str);

   i=0;
   j=strlen(str)-1;

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

   printf("\nReverse string is :%s",str);
}

OUTPUT:

Enter the string :BaronTuts

Reverse string is :stuTnoraB

 

Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen − 2 =