Module 10 · Strings
string.h: strlen, strcpy, strcmp, strcat
Free with an accountReading
Zara wants her program to say when one word sorts after another. She tried strcmp on two words written into the code, and it printed 1. So her test became if (strcmp(a, b) == 1). Then she read the words from the input, and the test never fired again.
Sign in to read
This lesson is free, with an account
An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.
What is inside string.h: strlen, strcpy, strcmp, strcat
- Zara's test that never fires
- Reading a string.h prototype
- strlen walks the whole string, every call
- strcpy needs room for the text and its zero
- strncpy is not the safe strcpy
- strcat joins, after you check the room
- strcmp walks to the first difference
- strchr and strstr answer yes or no