Skip to Main Content
Learn C the Hard Way: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C)
book

Learn C the Hard Way: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C)

by Zed A. Shaw
July 2015
Intermediate to advanced content levelIntermediate to advanced
380 pages
10h 15m
English
Addison-Wesley Professional
Content preview from Learn C the Hard Way: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C)

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern C for Absolute Beginners: A Friendly Introduction to the C Programming Language

Modern C for Absolute Beginners: A Friendly Introduction to the C Programming Language

Slobodan Dmitrović

Publisher Resources

ISBN: 9780133124385Purchase Link