basic libraries

  • C <stdio.h>
  • C <stdlib.h>
  • C <string.h>
  • C <math.h>
  • C <ctype.h>

cheatsheet

stdio.h (Standard Input/Output)

  1. printf - Prints formatted output to the console.
  2. scanf - Reads formatted input from the console.
  3. putchar - Writes a single character to the console.
  4. getchar - Reads a single character from the console.
  5. fopen - Opens a file.
  6. fclose - Closes an open file.
  7. fprintf - Writes formatted output to a file.
  8. fscanf - Reads formatted input from a file.
  9. fgets - Reads a string from a file or the console.
  10. fputs - Writes a string to a file or the console.
  11. fread - Reads binary data from a file.
  12. fwrite - Writes binary data to a file.
  13. feof - Checks if the end of a file has been reached.

stdlib.h (Standard Library Utilities)

  1. malloc - Allocates memory dynamically.
  2. calloc - Allocates and zeroes out memory dynamically.
  3. realloc - Resizes previously allocated memory.
  4. free - Frees dynamically allocated memory.
  5. atoi - Converts a string to an integer.
  6. atof - Converts a string to a float.
  7. strtol - Converts a string to a long integer.
  8. rand - Generates a pseudo-random number.
  9. srand - Seeds the random number generator.
  10. exit - Terminates the program.
  11. qsort - Sorts an array.
  12. bsearch - Searches for an element in a sorted array.

string.h (String Manipulation)

  1. strcpy - Copies a string.
  2. strncpy - Copies a string with a size limit.
  3. strcat - Concatenates two strings.
  4. strncat - Concatenates two strings with a size limit.
  5. strlen - Calculates the length of a string.
  6. strcmp - Compares two strings.
  7. strncmp - Compares two strings with a size limit.
  8. strchr - Finds the first occurrence of a character in a string.
  9. strrchr - Finds the last occurrence of a character in a string.
  10. strstr - Finds the first occurrence of a substring.
  11. strtok - Splits a string into tokens using a delimiter.
  12. memcpy - Copies a block of memory.
  13. memset - Fills a block of memory with a specified value.

math.h (Mathematical Functions)

  1. sqrt - Calculates the square root of a number.
  2. pow - Raises a number to a power.
  3. sin - Calculates the sine of an angle (in radians).
  4. cos - Calculates the cosine of an angle (in radians).
  5. tan - Calculates the tangent of an angle (in radians).
  6. log - Calculates the natural logarithm (base e).
  7. log10 - Calculates the base-10 logarithm.
  8. exp - Calculates the exponential function exe^x.
  9. ceil - Rounds a number up to the nearest integer.
  10. floor - Rounds a number down to the nearest integer.
  11. fabs - Calculates the absolute value of a floating-point number.
  12. fmod - Calculates the remainder of division.
  13. hypot - Calculates the hypotenuse of a right triangle (x2+y2\sqrt{x^2 + y^2}).

ctype.h (Character Classification and Conversion)

  1. isalpha - Checks if a character is an alphabetic letter.
  2. isdigit - Checks if a character is a digit (0–9).
  3. isalnum - Checks if a character is alphanumeric (letter or digit).
  4. isspace - Checks if a character is a whitespace character (e.g., space, tab).
  5. isupper - Checks if a character is an uppercase letter.
  6. islower - Checks if a character is a lowercase letter.
  7. toupper - Converts a character to uppercase.
  8. tolower - Converts a character to lowercase.
  9. ispunct - Checks if a character is a punctuation symbol.
  10. isprint - Checks if a character is printable.