O'Reilly logo

Learn C the Hard Way: A Clear & Direct Introduction To Modern C Programming by Zed A. Shaw

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

Exercise 36. Safer Strings

This exercise is designed to get you using bstring from now on, explain why C’s strings are an incredibly bad idea, and then have you change the liblcthw code to use bstring.

Why C Strings Were a Horrible Idea

When people talk about problems with C, they say its concept of a string is one of the top flaws. You’ve been using these extensively, and I’ve talked about the kinds of flaws they have, but there isn’t much that explains exactly why C strings are flawed and always will be. I’ll try to explain that right now, and after decades of using C’s strings, there’s enough evidence for me to say that they are just a bad idea.

It’s impossible to confirm that any given C string is valid:

• A C string is invalid if it doesn’t ...

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