I'm trying to call this search and replace function, and it says invalid memory access.
How should I modify the function, so that it would be possible to pass literal strings as arguments.
Code:
#include <stdio.h>
#include <string.h>
void function(const char * string){
char *pointer = strstr(string, "out");
if (pointer != NULL) {
memcpy(pointer, "in", 2);
memmove(pointer + 2, pointer + 3, strlen(pointer + 3) + 1);
}
printf("%s\n", string);
}
int main(void) {
function("cat is out roaming");
return 0;
}
Code:
75cc8e8a : at ???: RUNTIME ERROR: invalid memory access
../lib/bcheck.c:1699: by __bound_memcpy
replace_text.c:9: by function
replace_text.c:24: by main
Expected output: