[C language] Commonly used libraries and functions and corresponding functions

During regular programming:

  1. <stdio.h>: Provide standard input and output functions, such as printf, scanf, fprintf, fscanfetc.

  1. <stdlib.h>: Provides commonly used general functions, such as memory management functions ( malloc, calloc, realloc, free), random number functions ( rand, srand), string conversion functions ( atoi, atof, itoa), etc.

  1. <string.h>: Provide string processing functions, such as string copy function ( strcpy, strncpy), string concatenation function ( strcat, strncat), string comparison function ( strcmp, strncmp), string search function ( strchr, strstr), etc.

  1. <math.h>: Provides mathematical functions, such as commonly used mathematical operation functions ( sqrt, pow, sin, cos, logetc.) and mathematical constants ( M_PI, M_Eetc.).

  1. <ctype.h>: Provide character processing functions, such as character judgment functions ( isalpha, isdigit, islower, isupperetc.), character conversion functions ( tolower, toupper), etc.

  1. <time.h>: Provide time and date related functions, such as get current time function ( time), format time function ( strftime), delay function ( sleep), etc.

  1. <stdbool.h>: Define Boolean types and constants ( true, false), and provide related functions such as bool, true, and so on.false

These are just some common C standard libraries, there are many other widely used libraries, such as network programming libraries <net.h>, graphics libraries <graphics.h>, etc. According to different needs, you can choose the appropriate library to use the corresponding function.



Linux system programming

  1. <stdio.h>: Provides standard input and output functions for reading and outputting data.
    • printf(): Formatted output data to standard output.
    • scanf(): Read formatted data from standard input.
    • fopen():open a file.
    • fclose(): Close the file.

  1. <stdlib.h>: Functions that provide functions such as memory management, process control, and string conversion.
    • malloc(): Allocate a memory space of the specified size.
    • free(): Release the previously allocated memory space.
    • exit(): Terminate program execution.
    • atoi(): Converts a string to an integer.

  1. <unistd.h>: Provides system call functions for creating processes, executing programs, and communicating through pipes.
    • fork(): Create a new process.
    • exec(): Execute a new program.
    • pipe(): Create a pipeline.

  1. <fcntl.h>: Provides file operation related functions for opening, reading and writing files.
    • open():open a file.
    • read(): Read data from a file.
    • write(): Write data to the file.

  1. <sys/types.h>: Defines system data types, such as process ID, file descriptor, etc.

  1. <sys/stat.h>: Provides functions related to file status, such as obtaining file attributes, modifying file permissions, etc.
    • stat(): Get the properties of the file.

  1. <signal.h>: Provides signal processing related functions for capturing and processing signals.
    • signal(): Set the signal processing function.
    • kill(): Send a signal to the specified process.

  1. <pthread.h>: Provides thread-related functions for creating and managing threads.
    • pthread_create(): Create a new thread.
    • pthread_join(): Wait for the end of the thread.

  1. <netinet/in.h>: Provides network-related functions for creating and managing network connections.
    • socket(): Create a socket.
    • bind(): Bind the socket to a specific address and port.
    • listen(): Listen to the specified socket.

  1. <arpa/inet.h>: Provides a network address translation function for converting IP addresses and port numbers.
    • inet_addr(): Convert an IP address in dotted decimal notation to a 32-bit integer in network byte order.
    • inet_ntoa(): Convert a 32-bit integer in network byte order to an IP address in dotted decimal notation.

The functions in these header files can help developers implement various system-level functions, such as file operations, process management, and network communication. By calling these functions, you can easily interact with the operating system to complete the required functions.

Guess you like

Origin blog.csdn.net/Goforyouqp/article/details/132157164