I want to copy the a file name to a string and append ".cpt" to it. But I am unable to do this with safe functions (strcat_s). Error: "String is not null terminated!". And I did set '\0', how to fix this using safe functions?
size = strlen(locatie);
size++;
nieuw = (char*)malloc(size+4);
strcpy_s(nieuw, size, locatie);
nieuw[size] = '\0';
strcat_s(nieuw, 4, ".cpt"); // <-- crash
puts(nieuw);
The
size
parameter of the _s functions is the size of the destination buffer, not the source. The error is because there is no null terminator innieuw
in the first for characters. Try this: