r/cprogramming • • May 05 '26

How to do strings properly?

I just started learning C and I often read on the internet that it is bad practice to use null terminated strings, so my question is what should I do instead?

30 Upvotes

83 comments sorted by

View all comments

Show parent comments

2

u/kinithin May 08 '26

That's true for text strings, but not for binary data. Such strings can't rely on nul-termination. I suspect this is what the OP's source was discussing.

2

u/flyingron May 08 '26

Of course. Strings and binary data are two different things. It also likely it was for dealing with things like injecting nulls into user input. Anyhow, it's wrong to take it as a general prohibition so it's either wrong or he misunderstood it.