michael maire ex1-22

Discussion in 'C Programming' started by aegis, Dec 9, 2004.

  1. aegis

    aegis Guest

    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
     
    aegis, Dec 9, 2004
    #1
    1. Advertising

  2. aegis

    Michael Mair Guest

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

    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.
     
    Michael Mair, Dec 10, 2004
    #2
    1. Advertising

  3. aegis

    aegis Guest

    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.
     
    aegis, Dec 10, 2004
    #3
  4. aegis

    CBFalconer Guest

    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.mccaughan/g/remarks/uquote.html

    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
     
    CBFalconer, Dec 10, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony Lavinio
    Replies:
    0
    Views:
    537
    Tony Lavinio
    Mar 2, 2005
  2. Stylus Studio
    Replies:
    0
    Views:
    700
    Stylus Studio
    Dec 15, 2005
  3. El kroty

    k&r Ex1-24 without stack

    El kroty, Oct 21, 2004, in forum: C Programming
    Replies:
    7
    Views:
    341
    Dave Thompson
    Nov 1, 2004
  4. aegis

    k&r ex1-22

    aegis, Dec 8, 2004, in forum: C Programming
    Replies:
    1
    Views:
    366
    Michael Mair
    Dec 8, 2004
  5. ilan pillemer

    K&R2 Ex1-14

    ilan pillemer, Apr 1, 2007, in forum: C Programming
    Replies:
    3
    Views:
    343
    Malcolm McLean
    Apr 1, 2007
Loading...

Share This Page