liveBook · Manning

String.h

As explained in Modern C

string.h is the C standard library header declaring functions for manipulating character arrays and null-terminated strings.

Copying a program name

#include <string.h> size_t const len = strlen(argv[0]); char name[len+1]; memcpy(name, argv[0], len); name[len] = 0; if (!strcmp(name, argv[0])) printf("successfully copied\n");

string.h declares standard-library functions for manipulating character arrays and null-terminated strings. Names beginning with mem operate on arrays; names beginning with str require strings. section 6.1.5

The interfaces divide into two practical groups:

  • memcpy copies a specified number of characters between known-distinct arrays; memcmp compares array prefixes; memchr searches an array. section 6.1.5
  • strlen finds the first zero character, strcpy copies a zero-terminated source, and strcmp compares two strings lexicographically. section 6.1.5
  • A string argument must be zero-terminated, and a strcpy destination must be large enough for the copied string and its terminator. section 6.1.5

How Modern C covers it

How deep it goes
Defines representative functions, declarations, and termination requirements, but stops short of deeper implementation details.
Examples
Uses program-name copying and multiple character-array initializations to expose lengths, terminators, and destination sizing.
What it assumes
Assumes familiarity with char arrays and teaches the distinction between an array's size and a string's terminated length.
What you can do after
Apply string.h functions while checking zero termination, array lengths, and destination capacity.
How it connects
Connects character arrays with null-terminated strings, zero characters, lexicographic comparison, and ASCII character encoding.

Also explained in

Compare how 2 books explain string.h →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.