Write code to reverse C-style string.

Note:- c-string means that 'abcd' is represented as five characters, including the null character.

Algorithm:

Void reverse(char *str)
{
      char *end=str;
      char temp;
      if(str)
      {
           while(*end)
       {
            ++end;
       }
            --end;
            while(str < end)
            {
                  temp=*str;
                  *str++ =*end;
                  *end-- =temp;
            }
      }
}

Comments

Popular posts from this blog

Show that number of pendant vertices in a binary tree is (n+1)/2 ,where n is the number of vertices in the tree.

Prove that every tree with 2 or more vertices is 2-chromatic.

Top 5 websites to learn coding Online