Chapter 2.5. Strings: String theory

image with no caption

There’s more to strings than reading them.

You’ve seen how strings in C are actually char arrays but what does C allow you to do with them? That’s where string.h comes in. string.h is part of the C Standard Library that’s dedicated to string manipulation. If you want to concatenate strings together, copy one string to another, or compare two strings, the functions in string.h are there to help. In this chapter, you’ll see how to create an array of strings, and then take a close look at how to search within strings using the strstr() function.

Desperately seeking Susan Frank

There are so many tracks on the retro jukebox that people can’t find the music they are looking for. To help the customers, the guys in the Head First Lounge want you to write another program.

This is the track list:

image with no caption
image with no caption

The list is likely to get longer, so there’s just the first few tracks for now. You’ll need to write a C program that will ask the user which track she is looking for, and then get it to search through all of the tracks and display any that match.

Brain Power

There’ll be lots of strings in this program. How do you think you can record that information ...

Get Head First C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.