I am trying to remove the whitespace at the start of a string, I have the index of the first non whitespace character, so I tried to do this:
int firstNonWhitespace = ...;
char *line = ...;
char *realStart = line + firstNonWhiteSpace;
strcpy(line, realStart);
but got Abort Trap 6 when at runtime.
However it works if I copy the realStart string to a temporary string, and then copy the temporary string to line:
int firstNonWhitespace = ...;
char *line = ...;
char *realStart = line + firstNonWhiteSpace;
char *tstring = malloc(strlen(realStart) + 1);
strcpy(tstring, realStart);
strncpy(line, tstring, strlen(line));
free(tstring);