Menu Close

A List of C Library Functions and Header Files

Posted in C Programming

1.What is Header File Functions ?

Header file functions are functions that are declared in header files in C programming language. Header files are files that contain declarations of functions, variables, and constants that are used in a program. These declarations tell the compiler about the names, return types, parameter types, and argument orders of the functions that the program will use.

Header files are included in C programs using the preprocessor directive #include. The declarations in the header files allow the C program to call functions from other source files or libraries. By using header files, C programmers can avoid writing function prototypes or declarations repeatedly in every source file that uses the function. Instead, they can just include the header file in their source code.

Examples of header files that contain function declarations in C include stdio.h, stdlib.h, string.h, and math.h, among others. These files declare functions such as printf(), scanf(), malloc(), strcpy(), and sin(), respectively.

1.1 A List of Header File

  • stdio.h: Input/output operations
  • stdlib.h: General purpose functions including memory allocation, random number generation, and string conversion
  • math.h: Mathematical functions
  • string.h: String manipulation functions
  • time.h: Time and date functions
  • ctype.h: Character handling functions
  • stdbool.h: Boolean data type and operations
  • assert.h: Program assertion functions
  • limits.h: Implementation-defined constants such as integer size limits
  • float.h: Implementation-defined constants such as floating-point number size limits

There are many more header files available in C programming, but these are some of the most commonly used ones.

2. What is C library Functions ?

The C library functions, also known as the standard library functions, are a set of pre-written functions that are part of the C programming language standard. These functions provide common operations, such as input/output, string manipulation, memory allocation, and mathematical computations, among others.

The standard C library is specified in the ANSI C standard and is available on most platforms that support C programming. The functions can be called by including the appropriate header files in a C program. Examples of commonly used C library functions include printf(), scanf(), strlen(), malloc(), and pow().

2.1  a list of some common C Library functions

  1. printf() – used to print formatted text to the console or file.
  2. scanf() – used to read input from the console or file.
  3. malloc() – used to dynamically allocate memory.
  4. free() – used to free up previously allocated memory.
  5. strcpy() – used to copy a string from one location to another.
  6. strcmp() – used to compare two strings.
  7. strlen() – used to find the length of a string.
  8. fopen() – used to open a file.
  9. fclose() – used to close a file.
  10. fprintf() – used to write formatted text to a file.
  11. fscanf() – used to read formatted input from a file.
  12. rand() – used to generate a random number.
  13. time() – used to get the current time.
  14. exit() – used to terminate a program.
  15. system() – used to execute a system command.

These are just a few examples of the many functions available in the C library. Each function has its own specific purpose and can be used to perform a variety of tasks in a C program.

3. Header Files and Their Library Function List

Here is a list of common C header files and the library functions they provide:

  1. stdio.h – Provides input and output functions such as printf, scanf, and file operations like fopen and fclose.
  2. stdlib.h – Provides functions related to memory allocation and conversion of strings to numeric values, such as malloc, free, and atoi.
  3. string.h – Provides functions for manipulating strings such as strlen, strcpy, and strcmp.
  4. math.h – Provides mathematical functions like sin, cos, log, and pow.
  5. time.h – Provides functions for working with time and dates, such as time, localtime, and strftime.
  6. ctype.h – Provides functions for testing and converting characters such as isdigit, isalpha, and tolower.
  7. errno.h – Provides error numbers for system calls and library functions, and functions to retrieve and set them.
  8. assert.h – Provides a macro for debugging and error checking called assert.
  9. signal.h – Provides functions for signal handling, such as signal and raise.
  10. stdbool.h – Provides boolean data type and true/false constants.
  11. stddef.h – Provides macros for NULL pointer and offset calculations.
  12. limits.h – Provides constants for minimum and maximum values of integer data types.
  13. float.h – Provides constants for the characteristics of floating-point data types.
  14. setjmp.h – Provides a mechanism for non-local jumps, such as longjmp and setjmp.
  15. ctype.h – Provides functions for classifying and transforming characters.

Each of these header files includes a set of library functions that can be used in C programs. By including the appropriate header file, the functions defined in that file become available for use in the program.

a table that lists some commonly used C header files and their corresponding library functions:

Header File Library Functions
stdio.h printf, scanf, fopen, fclose
stdlib.h malloc, calloc, free, exit
string.h strlen, strcpy, strcat, strcmp
math.h sqrt, sin, cos, tan
time.h time, clock, gmtime, localtime
ctype.h isalpha, isdigit, islower, toupper
stdbool.h true, false, bool
assert.h assert
signal.h signal, raise
errno.h errno, perror

Note that this is not an exhaustive list, and there may be other library functions that are available within each header file.

Leave a Reply