Linux learning-Time Programming + file Programming

Source: Internet
Author: User

File programming and time programming:

1. There are two methods for file programming: System Call and c-library function call. The former depends on the linux operating system used, while the latter does not.

2. time Programming is to get the local time and use the time function to get the time!

I. File Creation

Write the following program file_creat.c (using the method called by the System)

1. creat (filename, 0666) creates a file function. filename is the file name, And 0666 indicates the file properties created. The value returned by this function is greater than 0.

2. EXIT_FAILURE = 1; EXIT_SUCCESS = 0

 

 

 

 

I. File copying (using library functions)

The procedure is as follows:

1. fopen (argv [1], "rb"), where argv [1] indicates the open file name, and "rb" indicates the open method.

2. In the fread (buffer, BUFFER_SIZE, from_fd) function, it indicates that the content in the file to which from_fd points should be read to the buffer cache!

3. fwrite (buffer, file_len, to_fd); the function indicates to write the content of file_len in buffer to the file pointed to by to_fd!

Ii. Time Programming

The Code is as follows: time. c

The above three methods can be converted to local time!

1. The structure of struct tm is as follows:

2. time (NULL) is a function used to obtain the calendar time. Its return value is a time_t type second value.

3. It is a function that converts a calendar time to a local time. The returned value is of the struct tm struct type.

4. The time obtained through the above step is only in the struct, so when we need a more intuitive time display, we need to use the following two functions.

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.