Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   michael maire ex1-22 (http://www.velocityreviews.com/forums/t436115-michael-maire-ex1-22-a.html)

aegis 12-09-2004 11:56 PM

michael maire ex1-22
 
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


Michael Mair 12-10-2004 12:45 AM

Re: michael maire ex1-22
 
Hello aegis,


one thing first: Please respond in the same thread -- there
may be other who can help you but are not aware what you
are referring to.
Whoever is interested: Start at the Message ID
<208eb33a.0412080617.548d9669@posting.google.com >

If you answer, then quote enough of the message you are
answering.

Apart from that, I do not think that a misspelled version
of my name is a decorative ingredient of subject lines.


aegis wrote:
> 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.


Well, the code I gave a link to does exactly what I propose
for line widths from 1 to INT_MAX-1.
About the spaces: Yes, I explicitly mention that I am of the
opinion that this is a cleaner solution. If you want to leave
the spaces in there: This actually simplifies everything, so
I do not see a problem there.

You asked whether you were interpreting the task description
in the right way and I responded that I think it describes
what I proposed.


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


Why? And why did you omit the space here if it is so
essential?


> 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


And how exactly does this relate to your code?

IMO, it comes down to that:
Either you are happy with your code, read my comments
about it and go on to the next exercise or you try to
implement what I suggested and come back if you need
help or a code review.


-Michael
--
E-Mail: Mine is a gmx dot de address.


aegis 12-10-2004 01:00 AM

Re: michael maire ex1-22
 
Write a program to ``fold'' long input lines into two or more shorter
lines after the last non-blank character that occurs before the n-th
column of input. Make sure your program does something intelligent with
very long lines, and if there are no blanks or tabs before the
specified column

where does it state that we should omit spaces in the line?
we only ensure that there is no space before the nth column.
which doesn't mean we omit spaces within the line.
the space can very well start at the beginning of the most newest line.
The "specified" column in the last sentence refers to the column
before the nth column. I think you read text that wasn't there.
your code uses stuff not introduced in the first chapter.


CBFalconer 12-10-2004 04:48 AM

Re: michael maire ex1-22
 
aegis wrote:
>
> Write a program to ``fold'' long input lines into two or more shorter

.... snip ...

Here you at least generated a reply to the previous article, but
you failed to quote any context. You should always quote enough so
that the article stands on its own, but please do not overquote,
i.e. snip anything that is not germane to your reply. Maintain
attribution lines for anything you quote.

Here are a few useful references. Read at least some of them.

http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.greenend.org.uk/rjk/2000/06/14/quoting.html
http://www.i-hate-computers.demon.co.uk/
http://web.ukonline.co.uk/g.mccaugha...ks/uquote.html

--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!



All times are GMT. The time now is 08:34 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.