-3

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);
Quentin
  • 62,093
  • 7
  • 131
  • 191
viki
  • 1
  • 1
  • suggest reading the man page for strcat() and comparing it to the man page for strcat_s(). The man page(s) are very informative about returned values. A 'google' of strcat will find plenty of references about the limitations of strcat() and the preference to use strncat(). – user3629249 Aug 12 '15 at 16:34
  • thanks for reference. – viki Aug 15 '15 at 14:46

1 Answers1

3

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.

IKavanagh
  • 6,089
  • 11
  • 42
  • 47