Step Into C · Lesson 8 · Arrays & Strings
Strings
Null-terminated char arrays, string.h, safe input with fgets.
- ~30 minreading and coding
- 4missions
- membersaccess
- Clanguage
Part of Step Into C. The full lesson, its missions and the real compiler and debugger are in the course. Try a free lesson first to see how it works.
C has no string type. A string is an array of char that ends with a null terminator: the byte '\0', whose value is 0. That terminator is how every string function knows where the text stops.
In this lesson
- A string is just bytes, with a zero at the end
- Declaring strings
- Printing and walking strings
- <string.h>
- Comparing strings
- Characters are arithmetic
- Reading a line safely: fgets
Missions
- Your own strlen
- SHOUT
- Who are you?
- Recognise a regular