When I have a string of unknown size and I create an char array to hold this string.I do something like this: #define LINE_END \r\nint line_end_size = strlen(LINE_END);char line[]=Hello! world.;int line_size=strlen(line);int test_line_size=line_size+line_end_size;char *test_line = malloc(test_line_size);strcpy(test_line,line);strcat(test_line,LINE_END);printf(test_line = );int index;for (index = 0; index<test_line_size+1; index++) /* plus 1 to see the null */    printf(%02X , (unsigned char)test_line[index]);printf(\n);Should I add 1 to the size of test_line_size to hold the NULL character?This must be compiled for linux32, win32, arm32.
Should I add 1 to my unknown string size when I create a char array to hold it via malloc?
array;malloc
If you treat it as a char array, then you don't need a 0 at the end. It's just an array like any other.But if you want to use string functions on it (like the strcpy, strcat in your example), those will look for, rsp. add a null terminator at the end of your arrays, so you will need the reserved space for it!Note that your strcat already writes this 0 past the end of the malloc'd space. If you used the mem... functions (like @zan-lynx commented), and iterated the array without the +1, it'd be perfectly fine (if unusual).