Albert wrote:
This isn't entirely related to C, but Kernighan and Ritchie asks in
Execise 1-18 of their C programming language book to 'Write a program
to remove trailing blanks and tabs from each line of input, and to
delete entirely blank lines'. What do they mean by trailing?
It means 'following'.
Let's consider <T> as a placeholder for a tab and <S> for a space. If
you have the line:
This<S>is<S>a<S><T>test.<S><S><T><S>
Then the trailing spaces are the ones following the last printable
character excluding the <S> and <T> characters themselves, i.e.
<S><S><T><S> so your result would be:
This<S>is<S>a<S><T>test.
If you have a line like:
<S><T><S><S>
then all those characters should be removed and you're left with an
empty string.
I think this is called trimming. Some languages offer 3 functions:
rtrim, ltrim and trim. rtrim trims the right (trailing) side of a
string, ltrim trims the left (leading) side and trim both sides. Python
has all three functions, although they're called rstrip, lstrip and
strip and don't necessarily work only for spaces and tabs. I don't
think C has any functions like that, although it should be easy to
write down something simple. I guess that's what you have to do :-)