Post

Appendix B: Standard Library Cheatsheet

Quick reference for common C standard library functions.

Appendix B: Standard Library Cheatsheet

Table of Contents

B.1 Input/Output

  • printf, scanf from <stdio.h>
  • fopen, fclose, fgets, fputs

B.2 String Handling

  • strcpy, strncpy, strlen, strcmp, strcat from <string.h>

B.3 Memory Management

  • malloc, calloc, realloc, free from <stdlib.h>

B.4 Math Functions

  • abs, sqrt, pow, sin, cos from <math.h>

B.5 Exercises

  1. Which function copies one string to another?
  2. How do you allocate memory for 10 integers?
  3. Which header provides file I/O functions?

B.6 Solutions

B.6.1 Solution 1

strcpy or strncpy.

B.6.2 Solution 2

malloc(10 * sizeof(int));

B.6.3 Solution 3

<stdio.h>

This post is licensed under CC BY 4.0 by the author.