I am doing this to append some text:
char text[100];
strcpy(text, "Hello");
char input[] = "random";
strncpy(text + strlen(text), input, sizeof(text) - strlen(text));
I did this and it seems to work fine for ASCII text. But I fear I am not being safe doing pointer arithmetic. What if the input is UTF-8?
FYI, when I do text + strlen(text) I am getting a pointer to the end of the sentence and then appending to the end of the sentence.
i.e.
text => |h|e|l|l|o|NUL||||||....
text + strlen(text) => |NUL|||||.....
strcat?text+1is not equal to text[1].strncpy, it is a dangerous and unsafe function only ever intended to be used for anything but ancient string formats in Unix. Better and safer alternatives arememcpyandstrcpy(with buffer size known/checked).