1. Problem description
scanf()
Both functions and gets()
functions can be used to input strings, but there are differences in functionality.
gets
Spaces can be accepted, and will be automatically added after the end'\0'
scanf
Encountering a space , carriage return and Tab will consider the input to be over, so it cannot receive spaces, and it will be automatically added after the end'\0'
But in C++, using gets
will report an error:
2. Solutions
After searching for information later, I found out that VS2015 does not support gets
it , and it becomes gets_s
, and the array name cannot be written alone in the brackets behind, and the number in the array needs to be added. The usage is as follows:
gets_s(words, STLEN);
At this point, the compilation will not report an error: