The size parameter of _s functions is the size of the destination buffer, not the source. The error is that in the nieuw character there is no null terminator in the first for characters. Try the following:
size = strlen(locatie); size++; int nieuwSize = size + 4; nieuw = (char*)malloc(nieuwSize ); strcpy_s(nieuw, nieuwSize, locatie); nieuw[size] = '\0'; strcat_s(nieuw, nieuwSize, ".cpt");
source share