This blog is designed to test exercise 1 to find problems and resolve them.
First, we compile with codeblocks for Exercise 1. The results are as follows:
You can see that the compiled Exercise 1 has no compile errors, only two warning, so let's test its functionality regardless of warning content.
So, let's analyze the Code section:
Char buff[10]; this line of code defines a 10-bit character array, so we want to consider the input when testing:
1. The Empty
2. Not null but less than 10 characters
3.10 character (s)
4. More than 10 characters
memset (buff,0,sizeof (Buff)); This line of code sets the buff pointer to empty in memory and sets the buff array to null.
Gets (buff); Gets the string function read from the standard input device. Can be read indefinitely without judging the upper limit to return to the end of the read. It is time to consider whether the overflow phenomenon.
printf ("\ n the buffer entered is [%s]\n", buff); Print the contents of the buff to the screen.
At this point we prepare several test cases:
1.null
2.a
[Email protected]
[Email protected]#$456
5.123456789123
To test separately
1. The test results are as follows
No problem
2. The test results are as follows
No problem
3. The test results are as follows
No problem
4. The test results are as follows
No problem
5. The test results are as follows
Error cannot be run we can find the cause of the array overflow, according to the actual situation we can choose whether to use dynamic array, or to specify the number of input character bits to solve the problem
Now we look back at two warning
This is an implicit declaration of the function of the warning, memset this function is not used in the included header file is declared, the workaround is to add a header file String.h
Exercise 1 Test