String input Problems
String input problems:
1. format the input function: scanf (Format String, address );. Match the data entered by the user with the formatted string, assign the matched data to the memory of the address, and use % s as the string format. Note that, when the input character exceeds the length of the array, it overwrites other data in the memory adjacent to the memory occupied by the array. And sometimes the system does not report an error. Assume that an array of 5 char strings is defined. When 12345abc is input, the memory space is simulated as follows:
2. Other input string functions:
(1). gets (array name or & variable name) function, get the string you entered and pass it to the array or variable. (I personally don't like it very much .) Using this function in xcode will directly report a warning in the console.
(2) import function: string. h
C language provides a set of library functions in: string. h, which are commonly used:
Strlen (string 1) calculates the length of the string.
Strcpy (string 1, string 2) assigns a value to string 1.
Strcat (string 1 string 2) append string 2 to string 1.
Strcmp (string 1, string 2) compares two strings. If the return value is positive, the former is large. If the return value is negative, the latter is large. If it is zero, the two strings are the same.