Library functions are a way to put functions into a library for others to use. The method is to put some commonly used functions into a file for different people to call. When calling, add the file name it is in to #include" to add it. Usually put in the lib file.
head FileIn C language family programs, header files are heavily used. In general, each C++/C program usually consists of a header file and a definition file. The header file is used as a carrier file containing function functions and data interface declarations. It is mainly used to save the declaration of the program, and the definition file is used to save the implementation of the program. .c is the program file you wrote.
Library function header fileC/C++ header file list
C, traditional C++
#include "assert.h" //Set the insertion point
#include "ctype.h" //Character Processing
#include "errno.h" //Define the error code
#include "float.h" //Floating point processing
#include "fstream.h" / / file input / output
#include "iomanip.h" //Parameterized input/output
#include "iostream.h" //Data stream input/output
#include "limits.h" / / define the most value constants of various data types
#include "locale.h" / / Define localization function
#include "math.h" //Define the math function
#include "stdio.h" //Define the input/output function
#include "stdlib.h" / / Define miscellaneous functions and memory allocation functions
#include "string.h" / / string processing
#include "strstrea.h" //Array-based input/output
#include 《time.h》 //Define the function about time
#include "wchar.h" //wide character processing and input/output
#include "wctype.h" //wide character classification
//////////////////////////////////////////////////////////// //////////////////////////
Standard C++ (not the same as above)
#include "algorithm" //STL general algorithm
#include "bitset" //STL bit set container
#include 《cctype》
#include "cerrno"
#include 《clocale》
#include 《cmath》
#include "complex" // plural classes
#include 《cstdio》
#include 《cstdlib》
#include 《cstring》
#include 《ctime》
#include "deque" //STL double-ended queue container
#include "Exception" //Exception handling class
#include 《fstream》
#include "functional" //STL defines the operation function (instead of the operator)
#include 《limits》
#include "list" //STL linear list container
#include "map" //STL mapping container
#include 《iomanip》
#include "ios" //Basic input/output support
#include "iosfwd" //predeclaration used by the input/output system
#include 《iostream》
#include "istream" //Basic input stream
#include "ostream" / / basic output stream
#include "queue" //STL queue container
#include "set" //STL collection container
#include "sstream" //string-based stream
#include "stack" //STL stack container
#include "stdexcept" //standard exception class
#include "streambuf" / / underlying input / output support
#include "string" //string class
#include "utility" //STL generic template class
#include "vector" //STL dynamic array container
#include 《cwchar》
#include 《cwctype》
Using namespace std;
//////////////////////////////////////////////////////////// //////////////////////////
C99 increase
#include "complex.h" //Multiple processing
#include "fenv.h" //Floating point environment
#include "inttypes.h" // integer format conversion
#include "stdbool.h" //Boolean environment
#include "stdint.h" //Integer environment
#include "tgmath.h" //General Type Mathematical Macro
C header file Daquan
-------------------------------------------------- -------------------------------------------------- ----------------------------------------
Classification function, the function library is ctype.h
Int isalpha(int ch) If ch is a letter ('A'-'Z', 'a'-'z') returns a non-zero value, otherwise returns 0
Int isalnum(int ch) If ch is a letter ('A'-'Z', 'a'-'z') or a number ('0'-'9') returns a non-zero value, otherwise returns 0
Int isascii(int ch) Returns a non-zero value if ch is a character (0-127 in ASCII), otherwise returns 0
Int iscntrl(int ch) Returns a non-zero value if ch is a void character (0x7F) or a normal control character (0x00-0x1F), otherwise returns 0
Int isdigit(int ch) Returns a non-zero value if ch is a number ('0'-'9'), otherwise returns 0
Int isgraph(int ch) Returns a non-zero value if ch is a printable character (without spaces) (0x21-0x7E), otherwise returns 0
Int islower(int ch) Returns a non-zero value if ch is a lowercase letter ('a'-'z'), otherwise returns 0
Int isprint(int ch) Returns a non-zero value if ch is a printable character (with spaces) (0x20-0x7E), otherwise returns 0
Int ispunct(int ch) Returns a non-zero value if ch is a punctuation character (0x00-0x1F), otherwise returns 0
Int isspace(int ch) If ch is a space (' '), horizontal tab (''), carriage return (''), paper feed ('\f'), vertical tab ('\v '), line feed ('') returns a non-zero value, otherwise returns 0
Int isupper(int ch) Returns a non-zero value if ch is an uppercase letter ('A'-'Z'), otherwise returns 0
Int isxdigit(int ch) If ch is a hexadecimal number ('0'-'9', 'A'-'F', 'a'-'f') returns a non-zero value, otherwise returns 0
Int tolower(int ch) If ch is an uppercase letter ('A'-'Z'), return the corresponding lowercase letter ('a'-'z')
Int toupper(int ch) If ch is a lowercase letter ('a'-'z'), return the corresponding uppercase letter ('A'-'Z')
-------------------------------------------------- -------------------------------------------------- ----------------------------------------
Math function, the function library is math.h, stdlib.h, string.h, float.h
Int abs(int i) returns the absolute value of the integer parameter i
Double cabs(struct complex znum) returns the absolute value of the complex znum
Double fabs(double x) returns the absolute value of the double precision parameter x
Long labs(long n) returns the absolute value of the long integer parameter n
Double exp(double x) returns the value of the exponential function ex
Double frexp(double value, int *eptr) returns the value of x in value=x*2n, where n is stored in eptr
Double ldexp(double value,int exp); returns the value of value*2exp
Double log(double x) returns the value of logex
Double log10(double x) returns the value of log10x
Double pow(double x,double y) returns the value of xy
Double pow10(int p) returns a value of 10p
Double sqrt(double x) returns the value of +√x
Double acos(double x) returns the inverse cosine cos-1(x) value of x, where x is radians
Double asin(double x) returns the inverse sine sin-1(x) value of x, where x is radians
Double atan(double x) returns the arc tangent tan-1(x) value of x, where x is radians
Double atan2(double y,double x) returns the tangent tan-1(x) value of y/x, where x is radians
Double cos(double x) returns the cosine cos(x) value of x, where x is radians
Double sin(double x) returns the sine sin(x) value of x, where x is radians
Double tan(double x) returns the tangent tan(x) value of x, where x is radians
Double cosh(double x) returns the hyperbolic cosine cosh(x) value of x, where x is radians
Double sinh(double x) returns the hyperbolic sine sinh(x) value of x, where x is radians
Double tanh(double x) returns the hyperbolic tangent tanh(x) value of x, where x is radians
Double hypot(double x,double y) returns the length (z) of the hypotenuse of the right triangle, x and y are the length of the right angle, z2=x2+y2
Double ceil(double x) returns the smallest integer not less than x
Double floor(double x) returns the largest integer not greater than x
Void srand(unsigned seed) Initialize random number generator
Int rand() produces a random number and returns this number
Double poly(double x, int n, double c[]) produces a polynomial from the argument
Double modf(double value,double *iptr) Decomposes the double value into a mantissa and a step
Double fmod(double x,double y) returns the remainder of x/y
Double frexp(double value, int *eptr) divides the double precision value into a mantissa and a step
Double atof(char *nptr) converts the string nptr to a floating point number and returns this floating point number
Double atoi(char *nptr) converts the string nptr to an integer and returns this integer
Double atol(char *nptr) converts the string nptr to an integer and returns this integer
Char *ecvt(double value, int ndigit, int *decpt, int *sign) Converts the float value to a string and returns the string
Char *fcvt(double value, int digitin, int *decpt, int *sign) converts the float value to a string and returns the string
Char *gcvt(double value, int ndigit, char *buf) converts the value of a value into a string and stores it in buf, and returns a pointer to buf
Char *ultoa(unsigned long value, char *string, int radix) Converts the unsigned integer value to a string and returns the string, radix is ​​the base used for the conversion
Char *ltoa(long value,char *string, int radix) Converts the long integer value to a string and returns the string, radix is ​​the base used for the conversion
Char *itoa(int value,char *string, int radix) Converts the integer value into a string and stores it in string. radix is ​​the base used in the conversion.
Double atof(char *nptr) converts the string nptr to a double, and returns this number, the error returns 0
Int atoi(char *nptr) converts the string nptr into an integer and returns this number. The error returns 0.
Long atol(char *nptr) converts the string nptr to an integer and returns this number. The error returns 0.
Double strtod(char *str,char **endptr) converts the string str to a double and returns this number.
Long strtol(char *str,char **endptr,int base) converts the string str to an integer and returns this number.
Int matherr(struct exception *e) User modify math error return information function (not necessary)
Double _matherr(_mexcep why,char *fun,double *arg1p, double *arg2p,double retval) User modify math error return information function (not necessary)
Unsigned int _clear87() clears the floating-point status word and returns to the original floating-point state
Void _fpreset() reinitialize floating point math package
Unsigned int _status87() returns the floating point status word
-------------------------------------------------- -------------------------------------------------- ----------------------------------------
Directory function, the function library is dir.h, dos.h
Int chdir(char *path) Makes the specified directory path (such as "C:\\WPS") into the current working directory and returns 0 successfully.
Int findfirst(char *pathname,struct ffblk *ffblk,int attrib) finds the specified file and returns 0 successfully.
Pathname is the specified directory name and file name, such as "C:\\WPS\\TXT"
Ffblk is a structure for specifying file information to be saved, as defined below:
â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”┓
┃struct ffblk ┃
┃{ ┃
┃ char ff_reserved[21]; ┃
┃ char ff_attrib; ┃
┃ int ff_ftime; ┃
┃ int ff_fdate; ┃
┃ long ff_fsize; ┃
┃ char ff_name[13]; ┃
┃} ┃
â”—â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”›
Attrib is a file attribute represented by the following characters
â”â”â”â”â”â”â”â”â”â”┳â”â”â”â”â”â”â”â”┓
┃FA_RDONLY read-only file ┃FA_LABEL volume label ┃
┃FA_HIDDEN hidden file ┃FA_DIREC directory┃
┃FA_SYSTEM system file ┃FA_ARCH file┃
â”—â”â”â”â”â”â”â”â”â”â”»â”â”â”â”â”â”â”â”â”›
example:
Struct ffblk ff;
Findfirst("*.wps",&ff,FA_RDONLY);
Int findnext(struct ffblk *ffblk) takes the file matching finddirst and returns 0 successfully.
Void fumerge(char *path,char *drive,char *dir,char *name,char *ext)
This function passes the drive letter (C:, A:, etc.), the path dir (\TC, \BC\LIB, etc.).
File name name (TC, WPS, etc.), extension ext (.EXE, .COM, etc.) to form a file name
Save with path.
Int fnsplit(char *path,char *drive,char *dir,char *name,char *ext)
This function breaks the file name path into the drive letter (C:, A:, etc.), the path dir (\TC, \BC\LIB, etc.).
The file name is name (TC, WPS, etc.), and the extension ext (.EXE, .COM, etc.) is stored in the corresponding variable.
Int getcurdir(int drive,char *direc) This function returns the current working directory name of the specified drive
Drive specified drive (0=current, 1=A, 2=B, 3=C, etc.)
Direc saves the variable of the current working path of the specified drive successfully returns 0
Char *getcwd(char *buf,iint n) This function takes the current working directory and stores it in buf until n words
The section is long. Error returns NULL
Int getdisk() takes the currently used drive and returns an integer (0=A, 1=B, 2=C, etc.)
Int setdisk(int drive) Set the drive drive to be used (0=A, 1=B, 2=C, etc.)
Returns the total number of drives available
Int mkdir(char *pathname) Create a new directory pathname and return 0 successfully.
Int rmdir(char *pathname) deletes a directory pathname and returns 0 successfully.
Char *mktemp(char *template) Constructs a file name that is not in the current directory and stores it in the template
Char *searchpath(char *pathname) Use MSDOS to find the path to the file filename.
, this function uses the DOS PATH variable, the file not found returns NULL
-------------------------------------------------- -------------------------------------------------- ----------------------------------------
Process function, the function library is stdlib.h, process.h
Void abort() This function writes a termination message to stderr by calling _exit with exit code 3.
And abnormally terminate the program. 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[])
The exec function family loads and runs the program pathname and sets the parameters
Arg0(arg1, arg2, argv[], envp[]) is passed to the subroutine, error returns -1
In the exec function family, the suffixes l, v, p, and e are added to exec.
The specified function will have some operational capability
With the suffix p, the function can use the DOS PATH variable to find the subroutine file.
l, the number of parameters passed in the function is fixed.
v, the number of parameters passed in the function is not fixed.
When e, the function passes the specified parameter envp, allowing the environment of the child process to be changed.
When there is no suffix e, the child process uses the environment of the current program.
Void _exit(int status) terminates the current program but does not clean up the scene
Void exit(int status) Terminates the current program, closes all files, writes the output of the buffer (waits for output),
And call the "export function" of any register, no return value
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 mode and sets the parameters
Arg0(arg1, arg2, argv[], envp[]) is passed to the subroutine. Error return -1
Mode is the operating mode
Mode is P_WAIT to return to the program after the subroutine is finished running.
P_NOWAIT means that the program is run at the same time when the subroutine is running (not available)
P_OVERLAY indicates that the subroutine is run after the program exits.
In the spawn function family, after the suffixes l, v, p, and e are added to the spawn,
The specified function will have some operational capability
When there is a suffix p, the function uses the DOS PATH to find the subroutine file.
l, the number of parameters passed by the function is fixed.
When v, the number of parameters passed by the function is not fixed.
When e, the specified parameter envp can be passed to the subroutine, allowing the subroutine runtime to be changed.
When there is no suffix e, the subroutine uses the environment of the program.
Int system(char *command) Pass the MSDOS command command to DOS to execute
-------------------------------------------------- -------------------------------------------------- ----------------------------------------
Conversion subroutine, the function library is math.h, stdlib.h, ctype.h, float.h
Char *ecvt(double value, int digit, int *decpt, int *sign)
Convert the float value to a string and return the string
Char *fcvt(double value, int digitin, int *decpt, int *sign)
Convert the float value to a string and return the string
Char *gcvt(double value, int ndigit, char *buf)
Convert the value to a string and store it in buf and return the pointer to buf
Char *ultoa(unsigned long value, char *string, int radix)
Converts the unsigned integer value to a string and returns the string, radix is ​​the base used for the conversion
Char *ltoa(long value,char *string,int radix)
Convert the long integer value to a string and return the string, radix is ​​the base used for the conversion
Char *itoa(int value,char *string,int radix)
Convert the integer value to a string and store it in string. radix is ​​the base used in the conversion.
Double atof(char *nptr) converts the string nptr to a double, and returns this number, the error returns 0
Int atoi(char *nptr) converts the string nptr into an integer and returns this number. The error returns 0.
Long atol(char *nptr) converts the string nptr to an integer and returns this number. The error returns 0.
Double strtod(char *str,char **endptr) converts the string str to a double and returns this number.
Long strtol(char *str,char **endptr,int base) converts the string str into an integer,
And return this number,
Int toascii(int c) returns the corresponding ASCII of c
Int tolower(int ch) If ch is an uppercase letter ('A'-'Z'), return the corresponding lowercase letter ('a'-'z')
Int _tolower(int ch) returns the corresponding lowercase letter of ch ('a'-'z')
Int toupper(int ch) If ch is a lowercase letter ('a'-'z'), return the corresponding uppercase letter ('A'-'Z')
Int _toupper(int ch) returns the corresponding uppercase letter of ch ('A'-'Z')
-------------------------------------------------- -------------------------------------------------- ----------------------------------------
Diagnostic function, the function library is assert.h, math.h
Void assert(int test) A macro that expands into an if statement. If the test fails,
Display a message and terminate the program abnormally, no return value
Void perror(char *string) This function will display the most recent error message in the following format:
String string: error message
Char *strerror(char *str) This function returns the most recent error message in the following format:
String str: error message
Int matherr(struct exception *e)
User modify math error return information function (not necessary)
Double _matherr(_mexcep why,char *fun,double *arg1p,
Double *arg2p, double retval)
User modify math error return information function (not necessary)
Input and output subroutine, the function library is io.h, conio.h, stat.h, dos.h, stdio.h, signal.h
Int kbhit() This function returns the most recently pressed 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), not displayed on the screen
Int putch() writes a character to the console (keyboard)
Int getchar() Read a character from the console (keyboard) and display it on the screen
Int putchar() writes a character to the console (keyboard)
Int getche() Read a character from the console (keyboard) and display it on the screen
Int ungetch(int c) Returns the character c back to the console (keyboard)
Char *cgets(char *string) read the string from the console (keyboard) and store it in string
Int scanf(char *format[,argument...]) reads a string from the console and performs each parameter separately.
Assignment, use BIOS to output
Int vscanf(char *format,Valist param) reads a string from the console and performs each parameter separately.
Assignment, use BIOS to output, parameters obtained from Valist param
Int cscanf(char *format[,argument...]) reads a string from the console and performs each parameter separately.
Assignment, directly to the console operation, such as the display when the display character is the direct write frequency display
Int sscanf (char *string, char *format[,argument,...]) through the string string, respectively
Parameter assignment
Int vsscanf (char *string, char *format, Vlist param) through the string string, respectively
Parameter assignment, parameters obtained from Vlist param
Int puts(char *string) sends a string string to the console (monitor),
Output using the BIOS
Void cputs(char *string) sends a string string to the console (monitor),
Directly operate the console, such as the display is directly write frequency display
Int printf(char *format[,argument,...]) Send formatted string output to console (monitor)
Output using the BIOS
Int vprintf(char *format,Valist param) Send formatted string output to console (monitor)
Use the BIOS for output, parameters obtained from Valist param
Int cprintf(char *format[,argument,...]) sends a formatted string output to the console (display),
Directly operate the console, such as the display is directly write frequency display
Int vcprintf(char *format,Valist param) sends a formatted string output to the console (display),
Directly operate the console, such as the display is a direct write frequency display,
Parameters obtained from Valist param
Int sprintf(char *string,char *format[,argument,...])
Rewrite the contents of the string string to the formatted string
Int vsprintf(char *string,char *format,Valist param)
Rewrite the contents of the string string as a formatted string, the parameters are taken from the Valist param
Int rename(char *oldname, char *newname) changes the name of the file oldname to newname
Int ioctl(int handle, int cmd[, int *argdx, int argcx])
This function is used to control the input / output device, please see the following table:
┌───┬────────────────────────────â”
│cmd value│function│
├───┼────────────────────────────┤
│ 0 │Remove device information│
│ 1 │Set device information│
│ 2 │Read argcx bytes into the address pointed to by argdx│
│ 3 │ write argcx byte at the address pointed to by argdx │
│ 4 │ except for the handle as the device number (0=current, 1=A, etc.), the same as cmd=2
│ 5 │ except for the handle as the device number (0=current, 1=A, etc.), the same as cmd=3
│ 6 │ take input status │
│ 7 │ take the output status │
│ 8 │ test interchangeability; only for DOS 3.x │
│ 11 │ Set the recalculation count of the sharing conflict; only for DOS 3.x │
└───┴────────────────────────────┘
Int (*ssignal(int sig, int(*action)())() executes software signals (not necessary)
Int gsignal(int sig) Execute software signal (not necessary)
Int _open(char *pathname, int access) opens a file for reading or writing.
Press and press access to determine whether to read or write the file. The access value is shown in the table below.
┌──────┬────────────────────â”
│access value│meaning│
├──────┼────────────────────┤
│O_RDONLY │Read File│
│O_WRONLY │Write a file│
│O_RDWR │ Read and write │
│O_NOINHERIT │ If the file is not passed to the subroutine, it is included │
│O_DENYALL │ only allows the current processing of files that must be accessed │
│O_DENYWRITE │ only allows reading from any other open file │
│O_DENYREAD │ only allows writing from any other open file │
│O_DENYNONE │Allow other shared open files│
└──────┴────────────────────┘
Int open(char *pathname, int access[, int permiss]) opens a file for reading or writing.
Press and press access to determine whether to read or write the file. The access value is shown in the table below.
┌────┬────────────────────â”
│access value│meaning│
├────┼────────────────────┤
│O_RDONLY│Read file│
│O_WRONLY│Write a file│
│O_RDWR │ Read and write │
│O_NDELAY│ is not used; compatible with UNIX systems│
│O_APPEND│ is read and written, but every write is always added at the end of the file │
│O_CREAT │ If the file exists, this flag is useless; if it does not exist, create a new file │
│O_TRUNC │ If the file exists, the length is truncated to 0, the attribute is unchanged │
│O_EXCL │Not used; compatible with UNIX systems│
│O_BINARY│This flag can be displayed to open the file in binary mode.
│O_TEXT │This flag can be used to display the text in a textual manner.
└────┴────────────────────┘
Permiss is a file attribute and can be the following values:
S_IWRITE allows writing S_IREAD to allow reading S_IREAD|S_IWRITE to allow reading and writing
Int creat(char *filename, int permiss) Create a new file filename and set it
Read and write. Permiss is file readable and can be the following value
S_IWRITE allows writing S_IREAD to allow reading S_IREAD|S_IWRITE to allow reading and writing
Int _creat(char *filename,int attrib) Create a new file filename and set the file
Attributes. Attrib is a file attribute and can be the following value
FA_RDONLY read-only FA_HIDDEN hides the FA_SYSTEM system
Int creatnew(char *filenamt,int attrib) Create a new file filename and set the file
Attributes. Attrib is a file attribute and can be the following value
FA_RDONLY read-only FA_HIDDEN hides the FA_SYSTEM system
Int creattemp(char *filenamt,int attrib) Create a new file filename and set the file
Attributes. Attrib is a file attribute and can be the following value
FA_RDONLY read-only FA_HIDDEN hides the FA_SYSTEM system
Int read(int handle,void *buf,int nbyte) reads nbyte characters from the file with the file number handle
Deposited in buf
Int _read(int handle,void *buf,int nbyte) reads nbyte characters from the file with the file number handle
Save it in buf and call MSDOS directly.
Int write(int handle, void *buf, int nbyte) writes nbyte characters in buf to file number
In the file for the handle
Int _write(int handle, void *buf, int nbyte) writes nbyte characters in buf to file number
In the file for the handle
Int dup(int handle) Copy a file handle pointer, return this pointer
Int dup2(int handle, int newhandle) Copy a file processing pointer handle to newhandle
Int eof(int *handle) checks if the file ends, returns 1 at the end, otherwise returns 0
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 with the file number as handle.
Opening mode
Int getftime(int handle,struct ftime *ftime) The time to read the file with the file number handle.
The file time is stored in the ftime structure, and 0 is successfully returned. The ftime structure is as follows:
┌──────────────────â”
│struct ftime │
│{ │
│ unsigned ft_tsec:5; │
│ unsigned ft_min:6; │
│ unsigned ft_hour:5; │
│ unsigned ft_day:5; │
│ unsigned ft_month:4; │
│ unsigned ft_year:1; │
│} │
└──────────────────┘
Int setftime(int handle,struct ftime *ftime) Rewrites the file time with the file number as handle.
The new time is in the structure ftime. Successfully returns 0. The structure ftime is as follows:
┌──────────────────â”
│struct ftime │
│{ │
│ unsigned ft_tsec:5; │
│ unsigned ft_min:6; │
│ unsigned ft_hour:5; │
│ unsigned ft_day:5; │
│ unsigned ft_month:4; │
│ unsigned ft_year:1; │
│} │
└──────────────────┘
Long lseek(int handle, long offset, int fromwhere) This function will use the file with the file number as handle.
The pointer is moved to the offset bytes after fromwhere.
SEEK_SET file switch SEEK_CUR current position SEEK_END file end
Long tell(int handle) This function returns the file pointer with the file number handle, expressed in bytes.
Int isatty(int handle) This function is used to get the type of device handle
Int lock(int handle, long offset, long length) Block file sharing
Int unlock(int handle, long offset, long length) Turns on blocking of file sharing
Int close(int handle) Closes the file processing represented by the handle. The handle is from _creat, creat,
File processing obtained by calling one of creatnew, creattemp, dup, dup2, _open, open
Successfully returns 0 or returns -1, available for UNIX systems
Int _close(int handle) Closes the file processing represented by the handle. The handle is from _creat, creat,
File processing obtained by calling one of creatnew, creattemp, dup, dup2, _open, open
Successfully returns 0 or returns -1, only for MSDOS system
FILE *fopen(char *filename,char *type) Open a file filename, open as type,
And return this file pointer, type can be suffixed with the following string
┌──┬────┬───────┬────────â”
│type│Reading and writing │Text/2-ary file│Build new/Open old file│
├──┼────┼───────┼────────┤
│r │Read│Text│Open old file│
│w │Write│Text│Build New File│
│a │Add│Text│Yes, open, no, new, new │
│r+ │Read/Write│Do not limit│Open│
│w+ │Read/Write│No Limit │New File│
│a+ │Read/Add │No Limit │If you open, Nothing will be built │
└──┴────┴───────┴────────┘
The suffixes that can be added are t and b. Add b to indicate that the file is operated in binary form, t is not necessary to use
Example: ┌──────────────────â”
│#include“stdio.h†│
│main() │
│{ │
│ FILE *fp; │
│ fp=fopen(“C:\\WPS\\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 stream and returns this character
Int putc(int ch,FILE *stream) writes a character ch to the stream stream
Int getw(FILE *stream) Reads an integer from the stream stream and returns EOF error
Int putw(int w,FILE *stream) writes an integer to the stream stream
Int ungetc(char c,FILE *stream) returns the character c back to the stream stream, the next read character will be c
Int fgetc(FILE *stream) Reads a character from the stream stream and returns this character
Int fputc(int ch,FILE *stream) Writes the character ch to the stream stream
Char *fgets(char *string, int n, FILE *stream) Read n characters from the stream stream and store them in string
Int fputs(char *string,FILE *stream) Write string string to stream stream
Int fread(void *ptr, int size, int nitems, FILE *stream) Read nitems from stream stream
A string of length size is stored in ptr
Int fwrite(void *ptr, int size, int nitems, FILE *stream) Write nitems to the stream stream
a string of length size, the string is in ptr
Int fscanf(FILE *stream,char *format[,argument,...]) in formatted form from stream stream
Read in a string
Int vfscanf(FILE *stream,char *format,Valist param) in formatted form from stream stream
Read in a string, the parameters are taken from Valist param
Int fprintf(FILE *stream,char *format[,argument,...]) takes a character in formatted form
String write to the specified stream stream
Int vfprintf(FILE *stream,char *format,Valist param) takes a character in formatted form
Write to the specified stream stream, the parameters are obtained from Valist param
Int fseek(FILE *stream, long offset, int fromwhere) function moves the file pointer to fromwhere
From the backward offset bytes of the pointed position, fromwhere can be the following values:
SEEK_SET file switch SEEK_CUR current position SEEK_END file end
Long ftell(FILE *stream) function returns the current file pointer position positioned in the stream, expressed in bytes
Int rewind(FILE *stream) Moves the current file pointer stream to the beginning of the file
int feof(FILE *stream) 检测æµstream上的文件指针是å¦åœ¨ç»“æŸä½ç½®
int fileno(FILE *stream) å–æµstream上的文件处ç†ï¼Œå¹¶è¿”回文件处ç†
int ferror(FILE *stream) 检测æµstream上是å¦æœ‰è¯»å†™é”™è¯¯ï¼Œå¦‚有错误就返回1
void clearerr(FILE *stream) 清除æµstream上的读写错误
void setbuf(FILE *stream,char *buf) ç»™æµstream指定一个缓冲区buf
void setvbuf(FILE *stream,char *buf,int type,unsigned size)
ç»™æµstream指定一个缓冲区buf,大å°ä¸ºsize,类型为type,type的值è§ä¸‹è¡¨
┌───┬───────────────────────────────â”
│type值│æ„义│
├───┼───────────────────────────────┤
│_IOFBF│文件是完全缓冲区,当缓冲区是空时,下一个输入æ“作将ä¼å›¾å¡«æ»¡æ•´ä¸ªç¼“│
│ │冲区。在输出时,在把任何数æ®å†™åˆ°æ–‡ä»¶ä¹‹å‰ï¼Œå°†å®Œå…¨å¡«å……缓冲区。 │
│_IOLBF│文件是行缓冲区。当缓冲区为空时,下一个输入æ“作将ä»ç„¶ä¼å›¾å¡«æ•´ä¸ªç¼“│
│ │冲区。然而在输出时,æ¯å½“新行符写到文件,缓冲区就被清洗掉。 │
│_IONBFâ”‚æ–‡ä»¶æ˜¯æ— ç¼“å†²çš„.bufå’Œsizeå‚数是被忽略的。æ¯ä¸ªè¾“å…¥æ“作将直接从文│
│ │件读,æ¯ä¸ªè¾“出æ“作将立å³æŠŠæ•°æ®å†™åˆ°æ–‡ä»¶ä¸ã€‚ │
└───┴───────────────────────────────┘
int fclose(FILE *stream) å…³é—一个æµï¼Œå¯ä»¥æ˜¯æ–‡ä»¶æˆ–设备(例如LPT1)
int fcloseall() å…³é—所有除stdin或stdout外的æµ
int fflush(FILE *stream) å…³é—一个æµï¼Œå¹¶å¯¹ç¼“冲区作处ç†
处ç†å³å¯¹è¯»çš„æµï¼Œå°†æµå†…内容读入缓冲区;
对写的æµï¼Œå°†ç¼“冲区内内容写入æµã€‚æˆåŠŸè¿”回0
int fflushall() å…³é—所有æµï¼Œå¹¶å¯¹æµå„自的缓冲区作处ç†
处ç†å³å¯¹è¯»çš„æµï¼Œå°†æµå†…内容读入缓冲区;
对写的æµï¼Œå°†ç¼“冲区内内容写入æµã€‚æˆåŠŸè¿”回0
int access(char *filename,int amode) 本函数检查文件filename并返回文件的属性,
函数将属性å˜äºŽamodeä¸ï¼Œamode由以下ä½çš„组åˆæž„æˆ
06å¯ä»¥è¯»ã€å†™04å¯ä»¥è¯»02å¯ä»¥å†™01执行(忽略的) 00文件å˜åœ¨
如果filename是一个目录,函数将åªç¡®å®šç›®å½•æ˜¯å¦å˜åœ¨
函数执行æˆåŠŸè¿”回0,å¦åˆ™è¿”回-1
int chmod(char *filename,int permiss) 本函数用于设定文件filename的属性
permisså¯ä»¥ä¸ºä»¥ä¸‹å€¼
S_IWRITEå…许写S_IREADå…许读S_IREAD|S_IWRITEå…许读ã€å†™
int _chmod(char *filename,int func[,int attrib]);
本函数用于读å–或设定文件filename的属性,
当func=0时,函数返回文件的属性;当func=1时,函数设定文件的属性
若为设定文件属性,attribå¯ä»¥ä¸ºä¸‹åˆ—常数之一
FA_RDONLYåªè¯»FA_HIDDENéšè—FA_SYSTEM系统
接å£å程åºï¼Œæ‰€åœ¨å‡½æ•°åº“为:dos.hã€bios.h
unsigned sleep(unsigned seconds)暂åœseconds微秒(百分之一秒)
int unlink(char *filenameï¼‰åˆ é™¤æ–‡ä»¶filename
unsigned FP_OFF(void far *farptr)本函数用æ¥å–远指针farptrçš„å移é‡
unsigned FP_SEG(void far *farptr)本函数用æ¥æ²¡ç½®è¿œæŒ‡é’ˆfarptr的段值
void far *MK_FP(unsigned seg,unsigned offï¼‰æ ¹æ®æ®µsegå’Œå移é‡offæž„é€ ä¸€ä¸ªfar指针
unsigned getpsp()å–程åºæ®µå‰ç¼€çš„段地å€ï¼Œå¹¶è¿”回这个地å€
char *parsfnm(char *cmdline,struct fcb *fcbptr,int option)
函数分æžä¸€ä¸ªå—符串,通常,对一个文件åæ¥è¯´ï¼Œæ˜¯ç”±cmdline所指的一个命令行。
文件å是放入一个FCBä¸ä½œä¸ºä¸€ä¸ªé©±åŠ¨å™¨ï¼Œæ–‡ä»¶å和扩展å.FCB是由fcbptr所指
定的.optionå‚数是DOS分æžç³»ç»Ÿè°ƒç”¨æ—¶ï¼ŒAL文本的值。
int absread(int drive,int nsects,int sectno,void *buffer)本函数功能为读特定的
ç£ç›˜æ‰‡åŒºï¼Œdrive为驱动器å·ï¼ˆ0=A,1=Bç‰ï¼‰ï¼Œnsects为è¦è¯»çš„扇区数,sectno为开始的逻
辑扇区å·ï¼Œbuffer为ä¿å˜æ‰€è¯»æ•°æ®çš„ä¿å˜ç©ºé—´
int abswrite(int drive,int nsects,int sectno,void *buffer)本函数功能为写特定的
ç£ç›˜æ‰‡åŒºï¼Œdrive为驱动器å·ï¼ˆ0=A,1=Bç‰ï¼‰ï¼Œnsects为è¦å†™çš„扇区数,sectno为开始的逻
辑扇区å·ï¼Œbuffer为ä¿å˜æ‰€å†™æ•°æ®çš„所在空间
void getdfree(int drive,struct dfree *dfreep)本函数用æ¥å–ç£ç›˜çš„自由空间,
drive为ç£ç›˜å·ï¼ˆ0=当å‰ï¼Œ1=Aç‰ï¼‰ã€‚函数将ç£ç›˜ç‰¹æ€§çš„ç”±dfreep指å‘çš„dfree结构ä¸ã€‚
dfree结构如下:
┌───────────────────â”
│struct dfree │
│{ │
│ unsigned df_avail; │
│ unsigned df_total; │
│ unsigned df_bsec; │
│ unsigned df_sclus; │
│} │
└───────────────────┘
char far *getdta() å–ç£ç›˜è½¬æ¢åœ°å€DTA
void setdta(char far *dta)设置ç£ç›˜è½¬æ¢åœ°å€DTA
void getfat(int drive,fatinfo *fatblkp)
本函数返回指定驱动器drive(0=当å‰ï¼Œ1=A,2=Bç‰ï¼‰çš„文件分é…表信æ¯
并å˜å…¥ç»“æž„fatblkpä¸ï¼Œç»“构如下:
┌──────────────────â”
│struct fatinfo │
│{ │
│ char fi_sclus; │
│ char fi_fatid; │
│ int fi_nclus; │
│ int fi_bysec; │
│} │
└──────────────────┘
void getfatd(struct fatinfo *fatblkp) 本函数返回当å‰é©±åŠ¨å™¨çš„文件分é…表信æ¯ï¼Œ
并å˜å…¥ç»“æž„fatblkpä¸ï¼Œç»“构如下:
┌──────────────────â”
│struct fatinfo │
│{ │
│ char fi_sclus; │
│ char fi_fatid; │
│ int fi_nclus; │
│ int fi_bysec; │
│} │
└──────────────────┘
int bdos(int dosfun,unsigned dosdx,unsigned dosal)本函数对MSDOS系统进行调用,
dosdx为寄å˜å™¨dx的值,dosal为寄å˜å™¨al的值,dosfun为功能å·
int bdosptr(int dosfun,void *argument,unsiigned dosal)本函数对MSDOS系统进行调用,
argument为寄å˜å™¨dx的值,dosal为寄å˜å™¨al的值,dosfun为功能å·
int int86(int intr_num,union REGS *inregs,union REGS *outregs)
执行intr_numå·ä¸æ–,用户定义的寄å˜å™¨å€¼å˜äºŽç»“æž„inregsä¸ï¼Œ
执行完åŽå°†è¿”回的寄å˜å™¨å€¼å˜äºŽç»“æž„outregsä¸ã€‚
int int86x(int intr_num,union REGS *inregs,union REGS *outregs,
struct SREGS *segregs)执行intr_numå·ä¸æ–,用户定义的寄å˜å™¨å€¼å˜äºŽ
结构inregsä¸å’Œç»“æž„segregsä¸ï¼Œæ‰§è¡Œå®ŒåŽå°†è¿”回的寄å˜å™¨å€¼å˜äºŽç»“æž„outregsä¸ã€‚
int intdos(union REGS *inregs,union REGS *outregs)
本函数执行DOSä¸æ–0x21æ¥è°ƒç”¨ä¸€ä¸ªæŒ‡å®šçš„DOS函数,用户定义的寄å˜å™¨å€¼
å˜äºŽç»“æž„inregsä¸ï¼Œæ‰§è¡Œå®ŒåŽå‡½æ•°å°†è¿”回的寄å˜å™¨å€¼å˜äºŽç»“æž„outregsä¸
int intdosx(union REGS *inregs,union REGS *outregs,struct SREGS *segregs)
本函数执行DOSä¸æ–0x21æ¥è°ƒç”¨ä¸€ä¸ªæŒ‡å®šçš„DOS函数,用户定义的寄å˜å™¨å€¼
å˜äºŽç»“æž„inregså’Œsegregsä¸ï¼Œæ‰§è¡Œå®ŒåŽå‡½æ•°å°†è¿”回的寄å˜å™¨å€¼å˜äºŽç»“æž„outregsä¸
void intr(int intr_num,struct REGPACK *preg)本函数ä¸ä¸€ä¸ªå¤‡ç”¨çš„8086软件ä¸æ–接å£
它能产生一个由å‚æ•°intr_num指定的8086软件ä¸æ–。函数在执行软件ä¸æ–å‰ï¼Œ
从结构pregå¤åˆ¶ç”¨æˆ·å®šä¹‰çš„å„寄å˜å™¨å€¼åˆ°å„个寄å˜å™¨ã€‚软件ä¸æ–完æˆåŽï¼Œ
函数将当å‰å„个寄å˜å™¨çš„值å¤åˆ¶åˆ°ç»“æž„pregä¸ã€‚å‚数如下:
intr_num 被执行的ä¸æ–å·
preg为ä¿å˜ç”¨æˆ·å®šä¹‰çš„寄å˜å™¨å€¼çš„结构,结构如下
┌──────────────────────â”
│struct REGPACK │
│{ │
│ unsigned r_ax,r_bx,r_cx,r_dx; │
│ unsigned r_bp,r_si,r_di,r_ds,r_es,r_flags; │
│} │
└──────────────────────┘
函数执行完åŽï¼Œå°†æ–°çš„寄å˜å™¨å€¼å˜äºŽç»“æž„pregä¸
void keep(int status,int size)以status状æ€è¿”回MSDOS,但程åºä»ä¿ç•™äºŽå†…å˜ä¸ï¼Œæ‰€å
用空间由size决定。
void ctrlbrk(int (*fptr)()) 设置ä¸æ–åŽçš„对ä¸æ–的处ç†ç¨‹åºã€‚
void disable() ç¦æ¢å‘生ä¸æ–
void enable() å…许å‘生ä¸æ–
void geninterrupt(int intr_num)执行由intr_num所指定的软件ä¸æ–
void interrupt(* getvect(int intr_num))() 返回ä¸æ–å·ä¸ºintr_numçš„ä¸æ–处ç†ç¨‹åºï¼Œ
例如: old_int_10h=getvect(0x10);
void setvect(int intr_num,void interrupt(* isr)()) 设置ä¸æ–å·ä¸ºintr_numçš„ä¸
æ–处ç†ç¨‹åºä¸ºisr,例如: setvect(0x10,new_int_10h);
void harderr(int (*fptr)()) 定义一个硬件错误处ç†ç¨‹åºï¼Œ
æ¯å½“出现错误时就调用fptr所指的程åº
void hardresume(int rescode)硬件错误处ç†å‡½æ•°
void hardretn(int errcode) 硬件错误处ç†å‡½æ•°
int inport(int prot) 从指定的输入端å£è¯»å…¥ä¸€ä¸ªå—,并返回这个å—
int inportb(int port)从指定的输入端å£è¯»å…¥ä¸€ä¸ªå—节,并返回这个å—节
void outport(int port,int word) å°†å—word写入指定的输出端å£port
void outportb(int port,char byte)将å—节byte写入指定的输出端å£port
int peek(int segment,unsigned offset) 函数返回segment:offset处的一个å—
char peekb(int segment,unsigned offset)函数返回segment:offset处的一个å—节
void poke(int segment,int offset,char value) å°†å—value写到segment:offset处
void pokeb(int segment,int offset,int value) å°†å—节value写到segment:offset处
int randbrd(struct fcb *fcbptr,int reccnt)
函数利用打开fcbptr所指的FCB读reccnt个记录。
int randbwr(struct fcb *fcbptr,int reccnt)
函数将fcbptr所指的FCBä¸çš„reccnt个记录写到ç£ç›˜ä¸Š
void segread(struct SREGS *segtbl)函数把段寄å˜å™¨çš„当å‰å€¼æ”¾è¿›ç»“æž„segtblä¸
64V Battery Pack ,Lithium Battery Box,Lithium Power Pack,Jackery Battery Pack
Zhejiang Casnovo Materials Co., Ltd. , https://www.casnovonewenergy.com