What i am trying to accomplish here is taking an cString and replacing a certain character with another which place i find via using the strchr() function.
what i can't figure out is how you can replace the character all my attempts (below commented out) all produce either an unedited string or crash the program. i believe i am going in the right direction with replacing the character (take the starting address of char *c and add n (the number of bytes forward the character i want to replace is) and then write to that new address.), but i can't seem to get it to function correctly.
any help is appreciated.
int main()
{
char *c, *sch;
int n;
c = "this is a test\n";
sch = strchr(c, 'a');
if(sch != NULL)
{
n = sch-c+1;
printf("%d\n", (int)sch);
printf("%d\n\n", (int)c);
printf("'a' found at: %d", n);
}
/////////////////////
//sch = &c;
//*(sch + n) = 'z';
/////////////////////
//*(c + n) = 'z';
/////////////////////
//c[n] = 'z';
/////////////////////
printf("\n\n%s", c);
getchar();
return 0;
}