C Standard Library Reference

POSIX and C99 standard library functions searchable by header and name.

Searchable C standard library reference organized by header — stdio.h, stdlib.h, string.h, math.h, ctype.h, time.h — with each function's prototype, purpose, and a usage note covering common pitfalls.

What is the difference between malloc and calloc?

malloc(size) allocates uninitialized memory of the given byte count. calloc(n, size) allocates an array of n elements, zero-initializes the whole block, and checks for multiplication overflow internally. Use calloc when you need zeroed memory or are allocating an array.

The C standard library is split across a handful of headers, each grouping related functions for I/O, memory, strings, math, and time. Calling the wrong one — or ignoring a return value — is a frequent source of bugs. This tool is a searchable reference covering each function’s prototype, purpose, and the pitfalls that bite C programmers.

How it works

Every function belongs to a header you must #include. The reference is grouped by header:

  • stdio.hprintf, scanf, fopen, fgets, fread, fwrite, fprintf, snprintf, fclose.
  • stdlib.hmalloc, calloc, realloc, free, atoi, strtol, qsort, bsearch, rand, exit.
  • string.hstrlen, strcpy, strncpy, strcmp, strcat, memcpy, memmove, memset, strstr.
  • ctype.hisdigit, isalpha, isspace, toupper, tolower.
  • math.hsqrt, pow, floor, ceil, fabs, fmod.
  • time.htime, clock, strftime, localtime.

Worked example

#include <stdio.h>
#include <string.h>

char buf[16];
fgets(buf, sizeof buf, stdin);   // bounded read — safe
buf[strcspn(buf, "\n")] = '\0';  // strip trailing newline

char dst[8];
snprintf(dst, sizeof dst, "%s", buf); // bounded copy, always NUL-terminated

fgets and snprintf take an explicit size, which is why they are preferred over gets and strcpy.

Notes

  • Return values carry the error signal: fopen returns NULL, allocation functions return NULL, and many stdio calls return EOF. Always check.
  • strncpy does not guarantee a terminating '\0' if the source is exactly as long as the buffer — terminate manually.
  • Prefer strtol/strtod over atoi/atof: they report conversion errors, while the ato* family silently returns 0 on bad input.
  • Functions tagged POSIX (strdup pre-C23, getline) are not part of plain standard C.