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;
}
}
}
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