Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Reversing a string without using library function

    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 556
    Comment on it

    In this c program we are reversing a string without using library function( Strrev). we are using a temporary variable store for reversing the string.

      #include<stdio.h>
      #include<string.h>
    
    int main() {
       char str[100], store ;
       int i, j = 0;
    
       printf("\nEnter the string :");
       gets(str);
    
       i = 0;
       j = strlen(str) - 1;
    
       while (i &lt; j) {
          store= str[i]; //the value at index i will be stored in store variable.
          str[i] = str[j];  // the value at index j will be stored in index i.
    
          str[j] = store;  // the value of store variable will be stored in index j
          i++;                // incrementing value of i by one.
          j--;                  // decrementing value of j by one.
       }
    
       printf("\nReverse string is :%s", str);
       return (0);
    }
    

    OUTPUT

    Enter the string  : Suresh
    Reverse string is :hseruS
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: