Unix/Linux Programming Practice tutorial 1 who Compilation

Source: Internet
Author: User
# Include <stdio. h>
# Include <utmp. h>
# Include <fcntl. h>
# Include <unistd. h>

The login user information is stored in/var/run/utmp.

Void perror (const char * s );
Print error information

1. Output string format Control
Printf ("% NS", STR) // outputs a string of the specified length. If it is too long, it is not truncated. The default value is right-aligned.

Printf ("%-ns", STR) // outputs a string of the specified length. If it is too long, it is not truncated. If it is not short, it is left aligned.

Printf ("% N. MS", STR) // outputs a string of the specified length. If the length is too long, the string is truncated. If the length is insufficient, the string is right aligned. N is the final output length of the string, and m is the length of the substring retrieved from the parameter string.

FD = open (utmp_file, o_rdwr); // open the file in read/write mode.

Strcmp (Rec. ut_line, myline); // compares two strings for equality. If the two strings are equal, 0 is returned.

The pointer in the file is associated with the file descriptor, rather than the file, so if twoProgramWhen you open a file at the same time, there will be two pointers, and the two programs will not interfere with each other's read operations.

# Include <sys/type. h>
# Include <unistd. h>

Off_t oldpos = lseek (int fd, off_t Dist, int base );
Base:
Start of seek_set File
Current location of seek_cur File
End of seek_end File

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.