I'm trying to replace a specific character in a string with a different character. I've tried doing the strchr method like other posts have suggested but I'm only getting a segfault.
char *str = "hello!\n";
char *ptr;
if((ptr = strchr(str, '\n')) != NULL) {
*ptr = '\0';
}