O'Reilly logo

Head First C by Dawn Griffiths, David Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 in C?

Create an array ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required