As shown below, I would like to enter a program that allows me to enter three strings and print out the three strings, but my program didn't work.
I don't even know why the "Please enter string 2" and "Please enter string 3" parts are not identified.How can I program it so that I can compile it well?c
Almost every line is bad, but if you explain why it's bad in order:
The variable definition below defines an area that contains 128 pointers to characters, not a storage area for strings (128 characters).
The following parameters specify the 128th pointer (which should not exist because it starts at 0th) in the pointer array to the letter s1.
This is the same as above.In fact,
segmentation fault has occurred without running up to this line."Also, the input values are displayed one by one without ""consolidation""."Do you mean that you couldn't get around to the consolidation process?
string 1 since you have specified the address value of the pointer that should not have been present (and not initialized): It is no surprise that is completed.
Segmentation fault occurs when the One
string 2: string 3: It was a coincidence that it ran until Two.
It would be better to use a new function with the following safety in mind.(Regarding the VC++ document)
strcpy_s, wcscpy_s, _mbscpy_s, _mbscpy_s_l
strcat_s, wcscat_s, _mbscat_s, _mbscat_s_l
In fact, it would be better to detect and deal with errors, but the program is as follows:An overview is provided in the comments.
This is what it looks like to fix it simply.
© 2022 OneMinuteCode. All rights reserved.