i think you misinterpreted the problem statement.
your suggestion seems to coincide with other
solutions where people stick newlines in the
line to act as a separator. but going this
route does not exhibit proper behavior when
your column width is very small. so this approach
can not be correct. also, if your input is
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
and the line is greater than column width
the line should be broken up into smaller segments
independent of column width. your solution also
eliminates spaces from the line.
if my column width is five and I have the line
"Hello World!"
then my output should be
"
Hello\n
Worl\n
d!\n
"
the space is *part* of the line and should not be
omitted.
here is a solution that I have looked at:
http://users.powernet.co.uk/eton/kandr2/krx122.html
it is a piece of junk. it can't even handle lines
longer than 120 characters.
again
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" is a line
and this program doesn't fold it and will also
segfault on lines larger than 120 characters.
[aegis@pluto ~] perl -e 'print "A" x 120' | ./krx122
Segmentation fault (core dumped)
[aegis@pluto ~]
see? piece of junk