This function should replace all instances of a character in a given character array, while returning the amount of characters changed, but I keep getting a segmentation fault at the highlighted area.
I'm only supposed to use pointers so arrays are out of the question, and I don't think we are allowed to use the string.h library as well.
Any ideas on how I could avoid something the segmentation fault or ways to fix it?
Code:int replaceChars(char replace, char find, char *input) { int i, j; //Finds length for(i = 0; *(input + (i + 1)) != '\0'; i++) ; int c = 0; for(j = 0; j <= i; j++) { if(*(input + j) == find) { *(input + j) = replace; //Segmentation fault happens here c++; } } return c; }