How to catch this exception?

Discussion in 'C Programming' started by Lord Gas, the Waxen, Jul 1, 2003.

  1. Lord Gas, the Waxen

    Blah Guest

    I don't have any documentation handy, but IIRC fgets() handles that
    detail for you, making the -1 above useful only if you want two bytes
    available at the end of your buffer.
     
    Blah, Jul 2, 2003
    #21
    1. Advertisements

  2. From the C99 standard:

    2 The fgets function reads at most one less than the number of
    characters specified by n from the stream pointed to by stream into
    the array pointed to by s. No additional characters are read after a
    new-line character (which is retained) or after end-of-file. A null
    character is written immediately after the last character read into
    the array.

    Martien
     
    Martien Verbruggen, Jul 2, 2003
    #22
    1. Advertisements

  3. Lord Gas, the Waxen

    Tom St Denis Guest

    I always -1 because some functions [recv(), strncpy if I recall] don't
    do this.

    Instead of consulting my C specs I just always -1. If I really need
    that 1 byte on a machine running 80 processes with 500MB of ram... then
    I ought to revise my algorithms/program...

    Tom
     
    Tom St Denis, Jul 2, 2003
    #23
  4. Lord Gas, the Waxen

    Dan Pop Guest

    The standard clearly says that a matching failure causes the function to
    return, right?

    Dan
     
    Dan Pop, Jul 2, 2003
    #24
  5. Lord Gas, the Waxen

    Dan Pop Guest

    That's what I suspected: it comes from your ignorance.

    Dan
     
    Dan Pop, Jul 2, 2003
    #25
  6. Oops. Sorry, Bertrand. I was looking at your name in the "From"
    field of my mail reader (Pine)'s main screen, which displays things like

    2868 Jul 1 Dan Pop (2476) . | | |-Re: How to catch th
    2869 Jul 1 To: comp.lang.c (2846) . | | | |-Re: How to catch
    2870 Jul 1 Bertrand Mollinier (2387) | | | |-Re: How to catc
    2871 Jul 2 Dan Pop (3004) | | | |-Re: How to catc

    (notice how all the fields get truncated). So I thought without
    double-checking that Mollinier *was* the whole name! Whoops!
    :)

    -Arthur
     
    Arthur J. O'Dwyer, Jul 2, 2003
    #26
  7. Groovy hepcat Lefteris Kororos was jivin' on Tue, 01 Jul 2003 23:02:18
    +0100 in comp.lang.c.
    Re: How to catch this exception?'s a cool scene! Dig it!
    Wrong! First of all, it's a null (or some people prefer NUL)
    terminator, not NULL. NULL is a macro that expands to a null pointer
    constant. And secondly, and more to the point, you do *not* have to
    take that into account, since fgets() already does so.

    --

    Dig the even newer still, yet more improved, sig!

    http://alphalink.com.au/~phaywood/
    "Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
    I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
     
    Peter Shaggy Haywood, Jul 4, 2003
    #27
  8. (Peter "Shaggy" Haywood) wrote in
    Yeah, I realized that after I posted. However, I found him labeling this
    behavior a problem with MSVC is what threw me off. FWIW, apologies to Tom
    for the snide remark.

    Sinan.
     
    A. Sinan Unur, Jul 5, 2003
    #28
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.