Some of the less common C-language functions in books

Source: Internet
Author: User

Function name: Getcwd#include <unistd.h>char *getcwd (char *buf, size_t size), function: Saves the absolute address of the current directory to buf, and the size of BUF. If size is too small to save the address, return NULL and set errno to Erange. You can take buf to null and make size negative to make GETCWD call malloc dynamically assign to buf, but in this case pay special attention to releasing the buffer after use to prevent a memory leak. program example if the directory is deleted (einval error) or if there is a change in permissions (eaccess error) while the program is running, GETCWD may also return null. Function Name: getenv: Takes a string from the environment, gets the value header file for the environment variable: stdlib.h usage: char *getenv (char *envvar), function Description: getenv () is used to get the contents of the parameter Envvar environment variable. The parameter envvar is the name of the environment variable and returns a pointer to that content if the variable exists. The format of the environment variable is envvar=value. The return value of the getenv function is stored in a global two-dimensional array, and you do not have to worry about overwriting the last invocation result when you use the GETENV function again. Return value: Execution succeeds returns a pointer to that content, and returns null if no matching environment variable name is found. If the variable exists but has no associated value, it will run successfully and return an empty string, that is, the first byte of the character is null. Function Name: STRCHR functions prototype: extern char *strchr (char *str,char character)

Parameter description: STR is a pointer to a string, character is a pending character

Library Name: #include <string.h>

function function: Find the first occurrence position of character character from the string str.

Return Description: Returns a pointer to the position of the first occurrence of the character character, or null if not found.

Other notes: There is also a format char *strchr (const char *string, int c), where the string is given in the int type.

Function name: Read ()Defining Functionsssize_t read[1] (int fd, void *buf, size_t count)return valueThe number of bytes read successfully returned, error 1 and set errno, if the end of the file is reached before the read, this time read returns 0ParametersThe parameter count is the number of bytes requested to be read, the data read is saved in the buffer buf, and the current read and write location of the file is moved backwards. Note that this read-write location may differ from the read/write location when using the C standard I/O library, which is recorded in the kernel, while the read and write location of the C standard I/O library is the location in the user space I/o buffer. For example, read a byte with fgetc, fgetc it is possible to read from the kernel 1024 bytes to the I/O buffer, and then return the first byte, when the file is recorded in the kernel read and write location is 1024, and in the file structure recorded in the read and write location is 1. Note that the return value type is ssize_t, which represents the signed size_t, which can return either a positive number of bytes, 0 (indicating the end of the file), or negative-1 (indicating an error). When the Read function returns, the return value shows how many bytes in the buf were just read. In some cases, the number of bytes actually read (the return value) is less than the number of bytes requested to be read, for example: When reading a regular file, the end of the file is reached before the Count bytes are read. For example, if you have 30 bytes from the end of the file and you request to read 100 bytes, read returns 30, and the next time read returns 0. related FunctionsOpen,close,lseek,fread,

Some of the less common C-language functions in books

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.