Solutions for the Kernighan and Ritchie

Discussion in 'C Programming' started by anotherlin@gmail.com, Oct 2, 2008.

  1. Guest

    Hi everyone,

    I've read the Kernighan and Ritchie some time ago, and then again, but
    this time I've done the full set of exercises. I figured it would be
    nice to share them :

    http://linkefong.free.fr/downloads/tcpl/tcpl-solutions-1.0.zip

    Your comments are welcome.

    I've of course didn't peek in Tondo and Gimpel's book or Richard
    Heathfield.

    Regards,
     
    , Oct 2, 2008
    #1
    1. Advertising

  2. On Oct 2, 6:10 pm, wrote:
    > Hi everyone,
    >
    > I've read the Kernighan and Ritchie some time ago, and then again, but
    > this time I've done the full set of exercises. I figured it would be
    > nice to share them :
    >
    > http://linkefong.free.fr/downloads/tcpl/tcpl-solutions-1.0.zip
    >
    > Your comments are welcome.
    >
    > I've of course didn't peek in Tondo and Gimpel's book or Richard
    > Heathfield.
    >
    > Regards,


    Nice!

    Since you like sharing your knowledge, you might be interested in
    contributing to the free software community by adding you project to
    savannah (savannah.gnu.org). In this way you could educate many
    people.

    Happy Hacking!
     
    freeasinfreedom, Oct 2, 2008
    #2
    1. Advertising

  3. user923005 Guest

    On Oct 2, 9:10 am, wrote:
    > Hi everyone,
    >
    > I've read the Kernighan and Ritchie some time ago, and then again, but
    > this time I've done the full set of exercises. I figured it would be
    > nice to share them :
    >
    > http://linkefong.free.fr/downloads/tcpl/tcpl-solutions-1.0.zip
    >
    > Your comments are welcome.
    >
    > I've of course didn't peek in Tondo and Gimpel's book or Richard
    > Heathfield.


    It might be nice to merge these solutions with Richard's collection
    that is online.
     
    user923005, Oct 2, 2008
    #3
  4. Guest

    I'll be glad to see them added to the clc-wiki. The admin has my
    blessing to upload them.

    I've basically answered all exercises, even those missing from
    Richard's collection.

    But first, is there somebody to check them for correctness? Any
    comments?
     
    , Oct 2, 2008
    #4
  5. Flash Gordon Guest

    wrote, On 02/10/08 23:09:
    > I'll be glad to see them added to the clc-wiki. The admin has my
    > blessing to upload them.


    Thanks for getting his/her blessing first. Please include a link to the
    original site when uploading them.

    > I've basically answered all exercises, even those missing from
    > Richard's collection.
    >
    > But first, is there somebody to check them for correctness? Any
    > comments?


    After uploading them they can be edited. So I would suggest upoading
    them then posting links to them here asking for comment.
    --
    Flash Gordon
    If spamming me sent it to
    If emailing me use my reply-to address
    See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
     
    Flash Gordon, Oct 3, 2008
    #5
  6. writes:

    > Hi everyone,
    >
    > I've read the Kernighan and Ritchie some time ago, and then again, but
    > this time I've done the full set of exercises. I figured it would be
    > nice to share them :
    >
    > http://linkefong.free.fr/downloads/tcpl/tcpl-solutions-1.0.zip
    >
    > Your comments are welcome.


    Looks good. That was a quick glance and if I have time I'll look
    again. On one style issue, I was baffled by the large number of blank
    lines. I won't make a fuss about style but it looked odd to me.

    I spent a bit more time on one that I am currently familiar with (the
    RPN calculator from chapter 4) and I am disappointed to see you also
    have lost the original (correct in my opinion) K&R design of passing
    getop the buffer size so you can prevent overflow. I'd count this as
    a error.

    --
    Ben.
     
    Ben Bacarisse, Oct 3, 2008
    #6
  7. user923005 Guest

    On Oct 2, 9:10 am, wrote:
    > Hi everyone,
    >
    > I've read the Kernighan and Ritchie some time ago, and then again, but
    > this time I've done the full set of exercises. I figured it would be
    > nice to share them :
    >
    > http://linkefong.free.fr/downloads/tcpl/tcpl-solutions-1.0.zip
    >
    > Your comments are welcome.
    >
    > I've of course didn't peek in Tondo and Gimpel's book or Richard
    > Heathfield.


    The test driver for exercise 4.2 does not test the atof() function:

    int main ()

    {
    printf("%g\n", 123.45e-6);
    return 0;
    }

    Probably, you meant to do this:

    #include <stdio.h>
    int main ()

    {
    printf("%g\n", atof("123.45e-6"));
    return 0;
    }
     
    user923005, Oct 3, 2008
    #7
  8. Richard Bos Guest

    freeasinfreedom <> wrote:

    > On Oct 2, 6:10 pm, wrote:
    > > I've read the Kernighan and Ritchie some time ago, and then again, but
    > > this time I've done the full set of exercises. I figured it would be
    > > nice to share them :
    > >
    > > http://linkefong.free.fr/downloads/tcpl/tcpl-solutions-1.0.zip


    [ Edited for honesty ]

    > Since you like sharing your knowledge, you might be interested in
    > contributing to the free software community by adding you project to
    > spammy (spamspam.spam.gnu.org).


    Or rather, do not, since I cannot find an Earthly reason why anyone
    would think answers to K&R exercises have anything to do with the
    contents of that page.

    Freedom? Freedom to advertise where it isn't wanted, apparently.

    Richard
     
    Richard Bos, Oct 3, 2008
    #8
  9. Guest

    > Looks good.  That was a quick glance and if I have time I'll look
    > again.  On one style issue, I was baffled by the large number of blank
    > lines.  I won't make a fuss about style but it looked odd to me.


    Well, I prefer things well separated. I use vi inside an 80x70
    characters
    xterm so there doesn't seem to be so much of them. I agree things can
    look
    differently and styles are a matter of personal taste.

    > I spent a bit more time on one that I am currently familiar with (the
    > RPN calculator from chapter 4) and I am disappointed to see you also
    > have lost the original (correct in my opinion) K&R design of passing
    > getop the buffer size so you can prevent overflow.  I'd count this as
    > a error.


    I started with the getop() function p78 of my 2nd edition book (41st
    printing)
    and there is no buffer size (prototype is int getop (char s[])). In
    fact, none
    of the exercises of this chapter specifically ask for checking buffer
    overflow.
    However, I agree that it would have been better a better answer.
     
    , Oct 3, 2008
    #9
  10. Guest

    > The test driver for exercise 4.2 does not test the atof() function:
    [...]

    Yes, you're right. I made a mistake and actually the atof() is not
    correctly
    tested and it has a bug! :( The exponent is not handled correctly, it
    can be
    fixed easily however. Thank you for pointing out this thing.
     
    , Oct 3, 2008
    #10
  11. Guest

    > > I'll be glad to see them added to the clc-wiki. The admin has my
    > > blessing to upload them.

    > Thanks for getting his/her blessing first. Please include a link to the
    > original site when uploading them.


    Ok, English is not my main language (I live in France). By "blessing",
    I
    meant "I authorize the admin to put the content of the zip archive on
    the
    clc-wiki. I do so very *happily*." Hence the "blessing". I apologize
    if I
    may have offended you.

    I read wikis a lot for various topics. But so far, I do not know how
    to
    write on them. And besides, it may be good first to check if the
    proposed
    answers are correct (exercise 4-2 has a bug as pointed out) before
    putting
    them on the wiki? Unless, the way is to put on the wiki and then
    correct
    them as needed?
     
    , Oct 3, 2008
    #11
  12. writes:
    <snip>
    >> I spent a bit more time on one that I am currently familiar with (the
    >> RPN calculator from chapter 4) and I am disappointed to see you also
    >> have lost the original (correct in my opinion) K&R design of passing
    >> getop the buffer size so you can prevent overflow.  I'd count this as
    >> a error.

    >
    > I started with the getop() function p78 of my 2nd edition book (41st
    > printing)
    > and there is no buffer size (prototype is int getop (char s[])). In
    > fact, none
    > of the exercises of this chapter specifically ask for checking buffer
    > overflow.
    > However, I agree that it would have been better a better answer.


    Well that explains why so many people have the same "fault". In my
    K&R (I don't have the 2nd edition) getop takes a char * and an int.
    Hardly surprising, the code check to ensure that the buffer passed is
    never overrun.

    I can't imagine why they'd go backwards, but it solves the mystery of
    so many solutions that look, to me, like backward steps!

    --
    Ben.
     
    Ben Bacarisse, Oct 3, 2008
    #12
  13. Flash Gordon Guest

    wrote, On 03/10/08 20:31:
    >>> I'll be glad to see them added to the clc-wiki. The admin has my
    >>> blessing to upload them.

    >> Thanks for getting his/her blessing first. Please include a link to the
    >> original site when uploading them.

    >
    > Ok, English is not my main language (I live in France). By "blessing",
    > I
    > meant "I authorize the admin to put the content of the zip archive on
    > the
    > clc-wiki. I do so very *happily*." Hence the "blessing". I apologize
    > if I
    > may have offended you.


    There was no offence taken. I miss-read what you said as saying that the
    admin of the site where they currently reside had given his/her blessing.

    Oh, and I only have admin access because I host it. I don't have any
    special control in terms of what is posted to the Wiki.

    > I read wikis a lot for various topics. But so far, I do not know how
    > to
    > write on them. And besides, it may be good first to check if the
    > proposed
    > answers are correct (exercise 4-2 has a bug as pointed out) before
    > putting
    > them on the wiki? Unless, the way is to put on the wiki and then
    > correct
    > them as needed?


    Wiki's are editable, so you can put them up and correct them. You do
    have to create yourself an account first.
    --
    Flash Gordon
    If spamming me sent it to
    If emailing me use my reply-to address
    See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
     
    Flash Gordon, Oct 4, 2008
    #13
  14. rideema

    Joined:
    Dec 17, 2008
    Messages:
    1
    New To Kr

    i m knew to C. can i know aerent the putchar and getchar are used in file handling ?? thn how in KR book it is being used in the first chapter itself ? shouldn't the operations like counting words etcbe performed on some file?:damnmate:
     
    rideema, Dec 17, 2008
    #14
    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. niclane
    Replies:
    9
    Views:
    370
    André Brière
    Jun 20, 2005
  2. Albert
    Replies:
    4
    Views:
    380
    Mike Wahler
    Dec 30, 2005
  3. Martjack Ecommerce
    Replies:
    0
    Views:
    554
    Martjack Ecommerce
    Dec 22, 2009
  4. sandeep

    Questions about K&R (Kernighan and Ritchi)

    sandeep, Apr 22, 2010, in forum: C Programming
    Replies:
    57
    Views:
    1,207
    Tim Rentsch
    Apr 29, 2010
  5. Cal Who
    Replies:
    0
    Views:
    483
    Cal Who
    Jun 9, 2010
Loading...

Share This Page