I am really in distress now after having spent so much time. Okay i tried using this modified approach but still it does not work . I don't understand what i am doing wrong now. Please ignore the printf statements as i was just trying to understand what it is doing at each step.
insert
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void xstrrev(char *);
int main(){
int i;
static char *s[] = {
"To err is human...",
"But to really mess things up...",
"One needs to know C!!"
};
for(i=0;i<3;i++){
printf("\n\rBefore reversal%s", s[i]);
xstrrev(s[i]);
}
return 0;
}
void xstrrev(char *a){
int len,i,j;
char *p, temp1, temp2;
//printf("\n\r%c %d", *a,a);
len = strlen(a);
printf("\n\r%d %d", len, len/2);
p = malloc(len+2);
printf("\n %d", p);
//printf("\n\r%d %c", p, *p);
while(*a != '\0'){
printf("\n %c", *a);
a++;
}
for(i = len;i>=0;i--){
*p = *a;
printf("\n %c", *p);
printf("\n %d", p);
//printf("\n %c", *a);
p++;
a--;
}
*p = '\0';
printf("\n%c", *p);
printf("\n %d", p);
p = p - (len+1);
printf("\n %d", p);
printf("\n\rAfter reversal%s", p);
}