Functions of Standard Library in C

The C Standard Library contains a vast array of functions categorized into various headers, each serving different purposes. Below is a list of some commonly used Standard Library headers and a brief overview of their primary functions. Please note that this list is not exhaustive, as there are many more functions and headers available for various purposes.

  1. stdio.h (Standard Input/Output):

    • printf(): Print formatted output to the console.
    • scanf(): Read formatted input from the console.
    • fopen(), fclose(), fread(), fwrite(): File I/O operations.
    • getchar(), putchar(): Read and write characters.
  2. stdlib.h (Standard Library):

    • malloc(), calloc(), realloc(), free(): Dynamic memory allocation and deallocation.
    • rand(), srand(): Generate random numbers.
    • exit(): Terminate program execution.
  3. string.h (String Manipulation):

    • strcpy(), strncpy(): Copy strings.
    • strcmp(), strncmp(): Compare strings.
    • strlen(): Calculate string length.
    • strcat(), strncat(): Concatenate strings.
    • strstr(): Find substring in a string.
  4. math.h (Mathematical Functions):

    • sqrt(), pow(), exp(), log(): Mathematical operations.
    • sin(), cos(), tan(): Trigonometric functions.
    • ceil(), floor(): Round numbers up or down.
    • rand(), srand(): Random number generation.
  5. ctype.h (Character Handling):

    • isalpha(), isdigit(), islower(), isupper(): Character classification.
    • tolower(), toupper(): Convert characters to lowercase or uppercase.
  6. time.h (Date and Time):

    • time(): Get current time.
    • ctime(): Convert time to a string.
    • difftime(): Calculate time differences.
    • strftime(): Format time as a string.
  7. stddef.h (Standard Definitions):

    • NULL: Null pointer constant.
    • size_t: Unsigned integer type used for sizes.
  8. stdbool.h (Boolean Type):

    • bool: Boolean data type (true or false).
  9. assert.h (Assertions):

    • assert(): Debugging aid to check program assumptions.
  10. stdarg.h (Variable Argument Lists):

    • va_start(), va_arg(), va_end(): Handle functions with a variable number of arguments (e.g., printf()).
  11. signal.h (Signal Handling):

    • signal(): Set signal-handling functions.
    • raise(): Raise signals in the program.
  12. locale.h (Locale and Internationalization):

    • setlocale(): Set the program's locale.
    • Functions for handling character encoding and internationalization.
  13. errno.h (Error Handling):

    • errno: Global variable containing error codes.
    • Functions like perror() to handle errors gracefully.
  14. stddef.h (Standard Definitions):

    • NULL: Null pointer constant.
    • size_t: Unsigned integer type used for sizes.
  15. fcntl.h (File Control):

    • open(), close(), read(), write(): File I/O operations with low-level control.
  16. sys/types.h and sys/stat.h (System Types and System Stat):

    • Data types and functions for dealing with system-related information and file attributes.
  17. unistd.h (POSIX Operating System API):

    • Functions for interacting with the operating system, including process control and file operations.
  18. math.h (Mathematical Functions):

    • fmod(), log10(), sinh(), cosh(), tanh(): Additional mathematical functions.

These are just some of the commonly used functions and headers from the C Standard Library. Each header contains a set of functions tailored to specific tasks, making C a versatile language for various programming needs. To utilize these functions, you typically include the relevant header at the beginning of your C source code file