Loading lessons...
C Cheatsheet: Common Functions
Cheatsheet: Common Functions
I/O (<stdio.h>)
- printf(format, ...)
- scanf(format, &var)
- puts(str) - string + newline
- fgets(buf, size, file) - safe line read
- fopen(name, "r") - open a file
Strings (<string.h>)
- strlen(s) - length
- strcpy(d, s) - copy string
- strcat(d, s) - append
- strcmp(a, b) - compare (0 = equal)
Memory (<stdlib.h>)
- malloc(size) - allocate
- free(ptr) - release
- calloc(n, size) - zeroed allocate
- realloc(p, size) - resize
Math (<math.h>)
- pow(x, y) - power
- sqrt(x) - square root
- fabs(x) - absolute (float)
- abs(x) - absolute (int)
TL;DR
- <string.h> for str functions.
- <stdlib.h> for malloc/free.
- <math.h> for math funcs.