Hi ,
I am unable to debug what is going with this program of reversing a string.
I had another doubt that is the assignment
*a = *p
valid because when i try to debug the program it gives error at this line in the program below that access violation writing at location whatever address is contained in a.
insertCode:
#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++){
xstrrev(s[i]);
printf("\n\r%s", s[i]);
}
return 0;
}
void xstrrev(char *a){
int len,j;
char *p, temp1, temp2;
//printf("\n\r%c %d", *a,a);
len = strlen(a);
//printf("\n\r%d %d", len, len/2);
p = a + len -1;
//printf("\n\r%d %c", p, *p);
for(j = 1;j<= len/2;j++){
temp1 = *a;
temp2 = *p;
printf("\n\r %c %c",*p, *a);
*a = *p;
printf("\n\r1\t%c\t%c",*a,*p);
// *p = temp;
//printf("\n\r2\t%c\t%c", *p, temp);
++a;
printf("\n\r3");
--p;
printf("\n\r4");
}
}