Does strcat() return an error as strcat_s() does?

387 views Asked by At

Does strcat() return an error as strcat_s() does? Can strcat() replace strcat_s()`?

 char str1[50] = "To be, or not to be, ";
 char str2[] = "that is the question.";
 int retval = strcat_s(str1, sizeof str1, str2);
 if(retval)
     printf("There was an error joining the strings. Error code = %d",retval);
 else
     printf("The combined strings:\n%s\n", str1);
1

There are 1 answers

0
IKavanagh On

strcat() does not return an error code but you can still use it incorrectly and run into errors. It can be used instead of strcat_s() like

strcat(str1, str2);

It may help you to look up a reference for C functions like cppreference.com/w/c to find out the answer to similar questions like this.