C function library Introduction: stdlib. H, process. H, Io. H, conio. H, stat. H, dos. H, stdio. H, signal. h

Source: Internet
Author: User
Tags uppercase letter

Process function. The function libraries are stdlib. h and process. h.


Void abort () This function writes a termination message to stderr by calling _ exit with exit code 3,
And terminate the program abnormally. No return value
Int exec... Load and run other programs
Int execl (char * pathname, char * arg0, char * arg1 ,..., Char * argn, null)
Int execle (char * pathname, char * arg0, char * arg1 ,...,
Char * argn, null, char * envp [])
Int execlp (char * pathname, char * arg0, char * arg1 ,..., Null)
Int execlpe (char * pathname, char * arg0, char * arg1 ,..., Null, char * envp [])
Int execv (char * pathname, char * argv [])
Int execve (char * pathname, char * argv [], char * envp [])
Int execvp (char * pathname, char * argv [])
Int execvpe (char * pathname, char * argv [], char * envp [])
Load and run the program pathname in the exec function family, and set the parameters
Arg0 (arg1, arg2, argv [], envp []) is passed to the subroutine. If an error occurs,-1 is returned.
In the exec function family, after the suffixes L, V, p, and E are added to exec,
The specified function has certain operation capability.
When the suffix P is available, the function can use the PATH variable of DOS to find the subroutine file.
L, the number of parameters passed in the function is fixed.
The number of parameters passed in the function is not fixed.
The function passes the specified parameter envp to change the environment of the sub-process,
When no suffix EIS available, the child process uses the environment of the current program.

Void _ exit (INT status) ends the current program, but the site is not cleared
Void exit (INT status) ends the current program, closes all files, writes the output of the buffer (waiting for output ),
And call the "exit function" of any register. No return value is returned.

Int spawn... Run subroutine
Int spawnl (INT mode, char * pathname, char * arg0, char * arg1 ,...,
Char * argn, null)
Int spawnle (INT mode, char * pathname, char * arg0, char * arg1 ,...,
Char * argn, null, char * envp [])
Int spawnlp (INT mode, char * pathname, char * arg0, char * arg1 ,...,
Char * argn, null)
Int spawnlpe (INT mode, char * pathname, char * arg0, char * arg1 ,...,
Char * argn, null, char * envp [])
Int spawnv (INT mode, char * pathname, char * argv [])
Int spawnve (INT mode, char * pathname, char * argv [], char * envp [])
Int spawnvp (INT mode, char * pathname, char * argv [])
Int spawnvpe (INT mode, char * pathname, char * argv [], char * envp [])
The spawn function family runs the subroutine pathname in mode and sets the Parameter
Arg0 (arg1, arg2, argv [], envp []) is passed to the subroutine. If an error occurs,-1 is returned.
Mode: Running Mode
When the mode is p_wait, the program is returned after the subroutine is run.
P_nowait indicates that the program is run simultaneously (unavailable) when the subroutine is run)
P_overlay indicates that a subroutine is run after the program exits.
In the spawn function family, after the suffixes L, V, p, and E are added to spawn,
The specified function has certain operation capability.
When the suffix P exists, the function uses the DOS path to find the subroutine file.
L, the number of parameters passed by the function is fixed.
The number of parameters passed by the function is not fixed.
The specified parameter envp can be passed to the subroutine to change the runtime environment of the subroutine.
When there is no suffix e, the subroutine uses the environment of this program.

INT system (char * command) transmits the msdos command to dos for execution.

Conversion subroutine. The function libraries include math. H, stdlib. H, ctype. H, and float. h.

Char * ECVT (double value, int ndigit, int * decpt, int * sign)
Converts a floating point value to a string and returns the string.
Char * fcvt (double value, int ndigit, int * decpt, int * sign)
Converts a floating point value to a string and returns the string.
Char * gcvt (double value, int ndigit, char * BUF)
Converts a number value to a string and saves it in the Buf, and returns the pointer of the Buf.
Char * ultoa (unsigned long value, char * string, int Radix)
Converts an unsigned integer value to a string and returns the string. Radix is the base number used for conversion.
Char * ltoa (long value, char * string, int Radix)
Converts a long integer value to a string and returns the string. Radix is the base number used for conversion.
Char * ITOA (INT value, char * string, int Radix)
Converts an integer value to a string and saves it to a string. Radix is the base number used for conversion.
Double atof (char * nptr) converts the string nptr to the double-precision number, and returns this number. The error returns 0.
Int atoi (char * nptr) converts the string nptr to an integer and returns this number. The error returns 0.
Long atol (char * nptr) converts the string nptr into a growth integer and returns this number. The error returns 0.
Double strtodd (char * STR, char ** endptr) converts a string STR into a double-precision number and returns this number,
Long strtol (char * STR, char ** endptr, int base) converts string STR into a growth integer,
And return this number,
Int toascii (INT c) returns the corresponding ASCII value of C.
Int tolower (INT ch) If ch is an upper-case letter ('A'-'Z'), the corresponding lower-case letter ('A'-'Z') is returned ')
Int _ tolower (INT ch) returns the corresponding lowercase letter ('A'-'Z') of Ch ')
Int toupper (INT ch) returns an uppercase letter ('A'-'Z') If ch is a lowercase letter ('A'-'Z ')
Int _ toupper (INT ch) returns the uppercase letter ('A'-'Z') of Ch ')

Diagnosis function. The function libraries are assert. h and math. h.
Void assert (INT test) is a macro that is extended to the IF statement. If test fails,
Displays a message and terminates the program with no returned value.
Void perror (char * string) This function displays the last error message in the following format:
String string: error message
Char * strerror (char * Str) This function returns the last error message in the following format:
String STR: error message
Int matherr (struct exception * E)
Function for returning information when a user modifies a mathematical error (not required)
Double _ matherr (_ mexcep why, char * Fun, double * arg1p,
Double * arg2p, double retval)
Function for returning information when a user modifies a mathematical error (not required)

Input and Output subroutines. function libraries include IO. H, conio. H, stat. H, dos. H, stdio. H, and signal. h.

Int kbhit () This function returns the recently typed button
Int fgetchar () reads a character from the console (keyboard) and displays it on the screen.
Int getch () reads a character from the console (keyboard) and is not displayed on the screen
Int putch () writes a character to the console (keyboard)
Int getchar () reads a character from the console (keyboard) and displays it on the screen.
Int putchar () writes a character to the console (keyboard)
Int getche () reads a character from the console (keyboard) and displays it on the screen.
Int ungetch (INT c) returns the character C to the console (keyboard)
Char * cgets (char * string) reads strings from the console (keyboard) and stores them in string
Int scanf (char * Format [, argument…]) Read a string from the console and perform
Assign values and use BIOS for output
Int vscanf (char * format, valist PARAM) reads a string from the console and performs
Assign values and use BIOS for output. The parameter is obtained from valist Param.
Int cscanf (char * Format [, argument…]) Read a string from the console and perform
Assign values directly to the console. For example, when the display is a character, it is displayed as a direct write frequency.
Int sscanf (char * string, char * Format [, argument,…]) Use string
Assign values to parameters
Int vsscanf (char * string, char * format, vlist PARAM)
Assign a value to the parameter. The parameter is obtained from vlist Param.
Int puts (char * string) sends a string to the console (Display ),
Output Using BIOS
Void cputs (char * string) sends a string to the console (Display ),
Directly operate on the console. For example, the display is displayed in direct write frequency mode.
Int printf (char * Format [, argument,…]) Send formatted string output to console (Display)
Output Using BIOS
Int vprintf (char * format, valist PARAM) sends formatted strings to the console (Display)
Use BIOS for output. The parameter is obtained from valist Param.
Int cprintf (char * Format [, argument,…]) Send formatted strings to the console (Display ),
Directly operate on the console. For example, the display is displayed in direct write frequency mode.
Int vcprintf (char * format, valist PARAM) sends formatted strings to the console (Display ),
Directly perform operations on the console. For example, the display is displayed in direct write frequency mode,
Parameters obtained from valist Param
Int sprintf (char * string, char * Format [, argument,…])
Rewrite the string content as a formatted string.
Int vsprintf (char * string, char * format, valist PARAM)
Rewrites the string content to the formatted string. The parameter is obtained from valist Param.
Int Rename (char * oldname, char * newname) change the file oldname to newname
Int IOCTL (INT handle, int cmd [, int * argdx, int argcx])
This function is used to control the input/output devices. See the following table:
┌ ── ─
│ Cmd value │ function │
├ ── ─
│ 0 │ retrieve device information │
│ 1 │ set device information │
│ 2 │ read argcx bytes into the address indicated by argdx │
│ 3 │ write argcx bytes at the address indicated by argdx │
│ 4 │ except handle as the device number (0 = Current, 1 = A, etc.), it is the same as when cmd = 2 │
│ 5 │ except handle as the device number (0 = Current, 1 = A, etc.), it is the same as when cmd = 3 │
│ 6 │ obtain the input status │
│ 7 │ obtain the output status │
│ 8 │ test maintainability; only for DOS 3.x │
│ 11 │ set the recalculation count for sharing conflicts; only for DOS 3.x │
└ ── ─
INT (* ssignal (INT Sig, INT (* Action) () executes software signals (not required)
Int gsignal (INT sig) Execution software signal (no need to use)

Int _ open (char * pathname, int access) opens a file for reading or writing,
Press Access to determine whether to read or write files. The access value is shown in the table below.
┌ ── ─ ┬ ── ─
│ Access value │ meaning │
├ ── ─ ┼ ── ─
│ O_rdonly │ read the file │
│ O_wronly │ write a file │
│ O_rdwr │ read and write │
│ O_noinherit │ if the file is not passed to the subroutine, it will be included │
│ O_denyall │ only allow currently processed files that must be accessed │
│ O_denywrite │ read only from any other open files │
│ O_denyread │ only allow writing from any other open files │
│ O_denynone │ allow other files to be shared and opened │
└ ── ─ ┴ ── ─
Int open (char * pathname, int access [, int permiss]) opens a file for reading or writing,
Press Access to determine whether to read or write files. The access value is shown in the table below.
┌ ── ─ ┬ ── ─ ┐
│ Access value │ meaning │
├ ── ─ ┼ ── ─ ┤
│ O_rdonly │ read the file │
│ O_wronly │ write a file │
│ O_rdwr │ read and write │
│ O_ndelay │ not used; compatible with Unix systems │
│ O_append │ read and write, but every write is always added at the end of the file │
│ O_creat │ if the file exists, this mark is useless; if it does not exist, create a new file │
│ O_trunc │ if the file exists, the length is truncated to 0, and the attribute remains unchanged │
│ O_excl │ unused; compatible with Unix systems │
│ O_binary │ this flag can be displayed to open a file in binary format │
│ O_text │ this flag can be used to display and open a file in text format │
└ ── ─ ┴ ── ─ ┘
Permiss is a File Attribute and can be set to the following values:
S_iwrite: s_iread | s_iwrite: Read and Write
Int creat (char * filename, int permiss) creates a new file filename and sets
Read/write. Permiss indicates file read/write. It can be the following values:
S_iwrite: s_iread | s_iwrite: Read and Write
Int _ creat (char * filename, int attrib) creates a new file filename and sets the file
Attribute. Attrib is a File Attribute and can be the following values:
Fa_rdonly read-only fa_hidden hide fa_system
Int creatnew (char * filenamt, int attrib) creates a new file filename and sets the file
Attribute. Attrib is a File Attribute and can be the following values:
Fa_rdonly read-only fa_hidden hide fa_system
Int creattemp (char * filenamt, int attrib) creates a new file filename and sets the file
Attribute. Attrib is a File Attribute and can be the following values:
Fa_rdonly read-only fa_hidden hide fa_system
Int read (INT handle, void * Buf, int nbyte) reads nbyte characters from the handle file.
Stored in Buf
Int _ read (INT handle, void * Buf, int nbyte) reads nbyte characters from the handle file.
Store it in the Buf and directly call msdos for operations.
Int write (INT handle, void * Buf, int nbyte) writes the nbyte characters in the Buf to the file number
In the handle file
Int _ write (INT handle, void * Buf, int nbyte) writes the nbyte characters in the Buf to the file number.
In the handle file
Int DUP (INT handle) copies a file processing pointer handle and returns this pointer.
Int dup2 (INT handle, int newhandle) copies a file processing pointer handle to newhandle
Int EOF (int * handle) checks whether the file is finished. If it ends, 1 is returned. Otherwise, 0 is returned.
Long filelength (INT handle) returns the file length. Handle is the file number.
Int setmode (INT handle, unsigned mode) This function is used to set the file number
Open Mode
Int getftime (INT handle, struct ftime * ftime) the time when the file number is handle,
Save the file time in the ftime structure, and 0 is returned successfully. The ftime structure is as follows:
┌ ── ─ ┐
│ Struct ftime │
│ {│
│ Unsigned ft_tsec: 5;/* seconds */│
│ Unsigned ft_min: 6;/* points */│
│ Unsigned ft_hour: 5;/*/│
│ Unsigned ft_day: 5;/* day */│
│ Unsigned ft_month: 4;/* month */│
│ Unsigned ft_year: 1;/* years-1980 */│
│} │
└ ── ─ ┘
Int setftime (INT handle, struct ftime * ftime) the time when the file number is overwritten by handle,
The new time is in the ftime structure. 0 is returned successfully. The ftime structure is as follows:
┌ ── ─ ┐
│ Struct ftime │
│ {│
│ Unsigned ft_tsec: 5;/* seconds */│
│ Unsigned ft_min: 6;/* points */│
│ Unsigned ft_hour: 5;/*/│
│ Unsigned ft_day: 5;/* day */│
│ Unsigned ft_month: 4;/* month */│
│ Unsigned ft_year: 1;/* years-1980 */│
│} │
└ ── ─ ┘
Long lseek (INT handle, long offset, int fromwhere) This function sets the file number as handle.
Pointer to the offset byte after fromwhere.
Seek_set file switch seek_cur current position seek_end file end
Long tell (INT handle) This function returns the pointer to the handle file, in bytes.
Int isatty (INT handle) This function is used to retrieve the device handle type
Int lock (INT handle, long offset, long length) blocks file sharing
Int unlock (INT handle, long offset, long length)
Int close (INT handle) closes the File Processing represented by handle. Handle is from _ creat, creat,
File Processing obtained by calling one of creatnew, creattemp, dup, dup2, _ open, and open
0 is returned. Otherwise,-1 is returned. It can be used in UNIX systems.
Int _ close (INT handle) disables the File Processing represented by handle. Handle is from _ creat, creat,
File Processing obtained by calling one of creatnew, creattemp, dup, dup2, _ open, and open
0 is returned. Otherwise,-1 is returned. It can only be used in msdos.

File * fopen (char * filename, char * type) open a file filename in the following way: type,
Returns the pointer to this file. type can be suffixed with the following string:
── ┬ ── ─
│ Type │ read/write │ text/2 hexadecimal file │ new/open old file │
── ┼ ── ─
│ R │ read │ text │ open old file │
│ W │ write │ text │ create a new file │
│ A │ add │ text │ If yes, open it. If no, create a new │
│ R + │ read/write │ unlimited │ open │
│ W + │ read/write │ no restrictions │ create a new file │
│ A + │ read/Add │ no restrictions │ If yes, open it. If no, create a new │
── ┴ ── ─
The suffixes T and B can be added. Adding B indicates that the file is operated in binary format and T is unnecessary.
For example, ┌ ── ─
│ # Include <stdio. h> │
│ Main () │
│ {│
│ File * FP; │
│ Fp = fopen ("C: // WPS. EXE", "R + B"); │
└ ── ─
File * fdopen (INT ahndle, char * type)
File * freopen (char * filename, char * type, file * Stream)
Int GETC (File * stream) reads a character from the stream and returns this character.
Int putc (int ch, file * stream) writes a character ch to the stream.
Int getw (File * stream) reads an integer from the stream, and an error is returned.
Int putw (int w, file * stream) writes an integer to the stream.
Int ungetc (char C, file * stream) returns the character C to the stream. The next read character will be C.
Int fgetc (File * stream) reads a character from the stream and returns this character.
Int fputc (int ch, file * stream) writes the character ch to the stream.
Char * fgets (char * string, int N, file * stream) reads n characters from stream and stores them in string
Int fputs (char * string, file * stream) writes string to stream
Int fread (void * PTR, int size, int nitems, file * stream) reads nitems from stream
Size strings are stored in PTR.
Int fwrite (void * PTR, int size, int nitems, file * stream) writes nitems to stream
String with a length of size in PTR
Int fscanf (File * stream, char * Format [, argument,…]) Formatted from stream
Read a string
Int vfscanf (File * stream, char * format, valist PARAM) formatted from stream
Reads a string and the parameter is obtained from valist Param.
Int fprintf (File * stream, char * Format [, argument,…]) Format a character
String to the specified stream
Int vfprintf (File * stream, char * format, valist PARAM) format a character
String to the specified stream. The parameter is obtained from valist Param.
Int fseek (File * stream, long offset, int fromwhere) function moves the file pointer to fromwhere
Fromwhere can be the following values:
Seek_set file switch seek_cur current position seek_end file end
The long ftell (File * stream) function returns the pointer position of the current file located in stream, expressed in bytes.
Int rewind (File * stream) moves the current file pointer stream to the beginning of the file
Int feof (File * stream) checks whether the file pointer on the stream is at the end position.
Int fileno (File * stream) takes the file processing on the stream and returns the file processing result.
Int ferror (File * stream) checks whether there is a read/write error in the stream. If there is an error, 1 is returned.
Void clearerr (File * stream) clears read/write errors on stream.
Void setbuf (File * stream, char * BUF) specifies a buffer Buf for stream
Void setvbuf (File * stream, char * Buf, int type, unsigned size)
Specify a buffer Buf for stream. The buffer size is size and the type is type. The value of type is shown in the table below.
┌ ── ─ ┐
│ Type value │ meaning │
├ ── ─ ┤
│ _ Iofbf │ the file is a full buffer. When the buffer is empty, the next input operation will attempt to fill up the entire cache │
│ Punch zone. During output, the buffer zone will be fully filled before writing any data to the file. │
│ _ Iolbf │ the file is a row buffer. When the buffer is empty, the next input operation will still attempt to fill in the entire │
│ Punch zone. However, during output, the buffer zone is cleaned whenever a new line character is written to a file. │
│ _ Ionbf │ the file is unbuffered. The Buf and size parameters are ignored. Each input operation will be directed to │
│ Read. Data is immediately written to the file for each output operation. │
└ ── ─ ┘
Int fclose (File * stream) disables a stream, which can be a file or device (such as LPT1)
Int fcloseall () disables all streams except stdin or stdout.
Int fflush (File * stream) closes a stream and processes the buffer.
Processing refers to reading the stream and reading the content in the stream into the buffer zone;
Write the content in the buffer to the stream. 0 is returned successfully.
Int fflushall () closes all streams and processes them in their respective buffers.
Processing refers to reading the stream and reading the content in the stream into the buffer zone;
Write the content in the buffer to the stream. 0 is returned successfully.

Int access (char * filename, int amode) This function checks the file filename and returns the file attributes,
The function stores attributes in amode, which is composed of the following digits.
06 read and write 04 read 02 write 01 execute (ignored) 00 file exist
If filename is a directory, the function only determines whether the directory exists.
If the function is successfully executed, 0 is returned. Otherwise,-1 is returned.
Int chmod (char * filename, int permiss) This function is used to set the filename attribute of a file.
Permiss can be the following values:
S_iwrite: s_iread | s_iwrite: Read and Write
Int _ chmod (char * filename, int func [, int attrib]);
This function is used to read or set the filename attribute of a file,
When func = 0, the function returns the attributes of the file; When func = 1, the function sets the attributes of the file.
If the file attribute is set, attrib can be one of the following constants.
Fa_rdonly read-only fa_hidden hide fa_system

 

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.