Trimming strings in c
Strings in C. They are wonderfully intuitive and easy to work with cough.
No, strings in C are a nightmare. Doing simple things such as trimming the
whitespace off the start or end of a string is complicated. Because a string
is not a string it's a char *
. Which means that if you want to do interesting
things you are going to have to get used to managing memory. Which means thinking,
and if there is one thing modern programmers hate, it's thinking.
Anyway, below I have added ltrim_string
, rtrim_string
, and trim_string
methods.
I've made the code as readable as I can, and documented it with tests.