I need to replace every occurence of '&' to ',' in a C string.
I did this and it works
Code 1:
char *val, *querydup;
.
.
.
val=strchr(querydup,'&');
while(val != NULL) {
*val=',';
val=strchr(querydup,'&');
}
In order to be "elegant" I tried the following, but it leads to seg fault, to the point where even my pointer cursor gets corrupted!. weird, I'm running linux inside a vmware vm.
Code 2:
while(val=strchr(querydup,'&') != NULL) {
*val=',';
}
So what could be wrong?..
Do you consider code 1 to be "elegant"?...
Regards.