Getting Segmentation Fault
All your examples are causing undefined behaviour, which might lead to a crash (or it might not appear to do any harm at all). You’re not allowed to change a string literal. (see e.g. here) You forgot to allocate storage for the terminating nul byte, do malloc(strlen(str) + 1); You’re calling free() on a pointer … Read more