Ch 10 · Strings · C

Topic 10 of 13 in C — Complete Tutorial (Beginner) — 2 lessons.

Strings are Char Arrays

C has no dedicated string type — a string is simply an array of char ending with a special invisible character '\0' (the null terminator) that marks where the text stops. You can create one easily with double quotes, and C adds the '\0' for you. You print strings with %s. Understanding that a string is just a char array (with a \0 at the end) is fundamental to C.

String Functions

Because strings are just char arrays, common operations live in the <string.h> library. strlen gives the length (not counting '\0'), strcpy copies one string into another, strcat joins them, and strcmp compares two strings (returning 0 when they are equal). You must include <string.h> to use these.

All topics in C Beginner

  1. Introduction to Programming & C
  2. Your First C Program
  3. Variables & Data Types
  4. Input & Output
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Functions
  9. Arrays
  10. Strings
  11. Pointers
  12. Structures
  13. Mini-Projects & Practice