basic libraries
- C <stdio.h>
- C <stdlib.h>
- C <string.h>
- C <math.h>
- C <ctype.h>
cheatsheet
stdio.h
(Standard Input/Output)
printf
- Prints formatted output to the console.scanf
- Reads formatted input from the console.putchar
- Writes a single character to the console.getchar
- Reads a single character from the console.fopen
- Opens a file.fclose
- Closes an open file.fprintf
- Writes formatted output to a file.fscanf
- Reads formatted input from a file.fgets
- Reads a string from a file or the console.fputs
- Writes a string to a file or the console.fread
- Reads binary data from a file.fwrite
- Writes binary data to a file.feof
- Checks if the end of a file has been reached.
stdlib.h
(Standard Library Utilities)
malloc
- Allocates memory dynamically.calloc
- Allocates and zeroes out memory dynamically.realloc
- Resizes previously allocated memory.free
- Frees dynamically allocated memory.atoi
- Converts a string to an integer.atof
- Converts a string to a float.strtol
- Converts a string to a long integer.rand
- Generates a pseudo-random number.srand
- Seeds the random number generator.exit
- Terminates the program.qsort
- Sorts an array.bsearch
- Searches for an element in a sorted array.
string.h
(String Manipulation)
strcpy
- Copies a string.strncpy
- Copies a string with a size limit.strcat
- Concatenates two strings.strncat
- Concatenates two strings with a size limit.strlen
- Calculates the length of a string.strcmp
- Compares two strings.strncmp
- Compares two strings with a size limit.strchr
- Finds the first occurrence of a character in a string.strrchr
- Finds the last occurrence of a character in a string.strstr
- Finds the first occurrence of a substring.strtok
- Splits a string into tokens using a delimiter.memcpy
- Copies a block of memory.memset
- Fills a block of memory with a specified value.
math.h
(Mathematical Functions)
sqrt
- Calculates the square root of a number.pow
- Raises a number to a power.sin
- Calculates the sine of an angle (in radians).cos
- Calculates the cosine of an angle (in radians).tan
- Calculates the tangent of an angle (in radians).log
- Calculates the natural logarithm (base e).log10
- Calculates the base-10 logarithm.exp
- Calculates the exponential function exe^x.ceil
- Rounds a number up to the nearest integer.floor
- Rounds a number down to the nearest integer.fabs
- Calculates the absolute value of a floating-point number.fmod
- Calculates the remainder of division.hypot
- Calculates the hypotenuse of a right triangle (x2+y2\sqrt{x^2 + y^2}).
ctype.h
(Character Classification and Conversion)
isalpha
- Checks if a character is an alphabetic letter.isdigit
- Checks if a character is a digit (0–9).isalnum
- Checks if a character is alphanumeric (letter or digit).isspace
- Checks if a character is a whitespace character (e.g., space, tab).isupper
- Checks if a character is an uppercase letter.islower
- Checks if a character is a lowercase letter.toupper
- Converts a character to uppercase.tolower
- Converts a character to lowercase.ispunct
- Checks if a character is a punctuation symbol.isprint
- Checks if a character is printable.