C Programming Tutorial

Advertisements

Write a program to reverse the string in C



       #include<stdio.h>
       #include<conio.h>

       void main()
       {

              char str[50],rev[50];
              int i,len=0;
              clrscr();

              printf("\nEnter any string : ");
              gets(str);
              
              for(i=0;str[i];i++)
                     len++;

              for(i=0;i<len;i++)
                     rev[i] = str[len -1 -i];
                     

              rev[i] = '\0';
              
              printf("\nString after reverse : %s",rev);

              getch();
    }

   Output : 

              Enter any string : hello world
              Reverse of string is : dlrow olleh




Advertisement