Good Programming habits in C Language (3)

Source: Internet
Author: User

1. each time a file calls an input/output function, a new ferror () function value is generated. Therefore, the ferror function value should be checked immediately after the input/output function is called, otherwise, the information will be lost.

2. The following two issues must be considered when using temporary files.

<1> ensure that the names of temporary files do not conflict with each other

<2> ensure that the content in the temporary file is not peeked, deleted, or modified by other users.

3. Consider the following when using a directory.

<1> information size. A directory is suitable for storing small amounts of information. You can use pointers to large files.

<2> information type. A directory is usually the property information.

<3> read/write ratio. If you need a large number of write operations, you can select a database.

<4> search capability.

<5> standard access.

4. If the I/O model is complete, the performance can be greatly improved, but I/O still wants to be slow. We recommend that you use multiple threads for some I/O operations. However, multithreading does not increase I/O speed on a large scale.

5. When using the rmdir () function, you must note that this function can only delete empty directories.

6. The DELTREE command deletes all specified directories, whether hidden or read-only.

7. before using the fnmerge () function to create a complete path name, check whether the required drive and directory exist.

8. array subscript always starts from 0. The variables that declare the array are always in lower case. When declaring an array, the variable name must be meaningful.

9. In fact, the C language does not check whether the array is out of bounds. Therefore, you must carefully check the code to check whether the code matches the actual requirements.

10. To save memory space, we recommend that you release useless pointers when writing program code.

11. When operating on arrays, you can use array symbols instead of pointer symbols. This method may increase the program time, but can enhance the readability of the program.

12. a null pointer cannot be referenced indirectly.

13. When using a pointer function, because the return value is an address, the type specifier is generally int.

14. When writing a program, try not to use multi-level pointers, which may reduce the readability of the program.

15. The program structure that is not clearly described in the language can be expressed in diagrams, which makes it easy to understand the meaning of the program.

Related Article

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.