On this page
  1. scanf
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

scanf

Prev: gets | Up: stdio.h | Next: stdlib.h
Rel: fgets(), stdio.h, stdio.h & File I/O Guide
Ref: cppreference — scanf
Tags: #public #prog #c #stdlib #stdio #tier/legacy


Include

#include <stdio.h>

Signature & Overview

int scanf(const char *restrict fmt, ...);

Reads formatted input from stdin; prone to unbounded %s reads, integer overflow UB, and leftover newline issues.

Legacy / Avoid: Prefer fgets() in all new code.

Notes & Pitfalls

Example

#include <assert.h>
#include <stdio.h>

int main(void) {
    int port = 0;
    assert(sscanf("port=8080", "port=%d", &port) == 1 && port == 8080);
}

Linked from

Related notes