Exercise 1 Test

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.