Skip to main content

How to reverse a String without using C functions

How to reverse a String without using C functions ?
the above is slightly wrong
this is the corrected one..
char * rev_string (char * str)
{
char temp;
int i , j;
for (i = 0 ; str[i]!= '\0' ; i++);
for(j = 0 ; j < i ; j++ , i--)
{
temp = str[j];
str[j] = str[i];
str[i] = temp;
}
return str;
}
#include<stdio.h>
void reverse(char *);
void main()
{
char str[]="Hello";
reverse(str);
printf("Reverse String is %s",str);
}
void reverse(char *p)
{
char *q=p;
while(*++q!='\0');
q--;
while(p<q)
{
*p=*p+*q;
*q=*p-*q;
*p=*p-*q;
p++;
q--;
}
}
 blog it

Comments

Bhagwat said…
In first case, decrement i before going to loop, ie i--; before compare loop.