void main() {
void strrev(char *);
char *p="GOOd";
strrev(p);
printf("%s",p);
}
void strrev(char *str) {
char temp, *end_ptr;
if( str == NULL || !(*str) ) return;
end_ptr = str + strlen(str) - 1;
while( end_ptr > str )
{
temp = *str;
*str = *end_ptr;
*end_ptr = temp; str++;
end_ptr--;
}
}
i am getting the error segmentation failed can any one help me out how to sort it out…
One problem is that in the following:
the compiler is allowed to place the string literal in read-only memory.
Any attempt to modify the string pointed to by
presults in undefined behaviour.Try changing the above line to:
I don’t see anything wrong with the
strrev()function itself.