Hi, what's wrong with this code? I just followed the requirements of using strcat.
Code:#include<stdio.h> #include<string.h> int main() { char arr2[]="I love mom"; char arr3[]="45"; strcat(arr2,arr3); printf("%s", arr2); return 0; }
Hi, what's wrong with this code? I just followed the requirements of using strcat.
Code:#include<stdio.h> #include<string.h> int main() { char arr2[]="I love mom"; char arr3[]="45"; strcat(arr2,arr3); printf("%s", arr2); return 0; }
Last edited by Romyo2; 08-13-2015 at 07:53 AM.
arr2 has no space for any characters to be concatenated to it, i.e., it fails the requirement that there be enough space for strcat to write to without going out of bounds.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
> I just followed the requirements of using strcat.
Perhaps you didn’t follow it to an extend where it explicitly specified this
I would also suggest that you use strncat. Rather than strcat which will help great deal in avoiding potential buffer overflow sequences"Pointer to the destination array, which should contain a C string, and be large enough to contain the concatenated resulting string."
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein