Hi I may be asking something silly but after searching on online and playing around getting I still getting it wrong.
What I am trying to do is from a string of characters pick a one and replacing with two.
so let said you have char *string_char = "blabla'blabla";
so I have wrote something like:
Code:
char* adding_character3 (char* str)
{
char *a;
char *p;
char temp = 0;
for (a = p = str; *p != '\0'; ++p)
{
if (*p == 39){
*a++ = 39;
*a++ = 39;
}else{
*a++ = *p;
}
}
*a = 0;
return a;
}
There is something I may be missing in term as knowledge? in the loop the following statement "a = p = str" synchronize all the address every time it increment?
The above code will give a seg fault.
What I want to is a output : "blabla''blabla"
I also try to leave "*a" out of the loop and keep loading and incrementing as it goes alone incrementing in the loop but that didnt work. What is the best way to debug "segmentation faults"?