Problem reading data from file and record it for use in program

This is a discussion on Problem reading data from file and record it for use in program within the C Programming forums, part of the General Programming Boards category; My output: Code: items = 0, key = "", value = "", n = 0 So what conclusion did we ...

  1. #16
    FOX
    Join Date
    May 2005
    Posts
    188
    My output:
    Code:
    items = 0, key = "", value = "", n = 0
    So what conclusion did we come to?
    You can't use %<number>[...] or %*[...]?

    Furthermore:
    Code:
           n      Nothing is expected; instead, the number of characters  consumed
                  thus  far  from  the  input  is stored through the next pointer,
                  which must be a pointer to  int.   This  is  not  a  conversion,
                  although  it  can be suppressed with the * flag.  The C standard
                  says: `Execution of  a  %n  directive  does  not  increment  the
                  assignment  count  returned  at the completion of execution' but
                  the Corrigendum seems to contradict this. Probably  it  is  wise
                  not  to  make any assumptions on the effect of %n conversions on
                  the return value.
    Now that's just great... *Curses at my K&R book *

  2. #17
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >So what conclusion did we come to?

    That BC55 is broken.

    >You can't use %<number>[...] or %*[...]?

    ...with %n(?).
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #18
    FOX
    Join Date
    May 2005
    Posts
    188
    > ...with %n(?).
    What does n refer to in the following context:
    n [...]If the conversion specification includes an assignment suppressing character or a field width, the behavior is undefined.
    I thought it meant that you can't specify a field width for [...], like this:
    Code:
    %39[...] /* Undefined? */
    or suppress the result with *:
    Code:
    %*[...] /* Undefined? */
    And was the code you posted before supposed to work? My output from GCC did not match yours.
    Last edited by ^xor; 06-11-2005 at 01:50 PM.

  4. #19
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >What does n refer to in the following context:

    I'm taking it to mean that a specifier such as
    Code:
    "%39[...]%n" // or
    "%*[...]%n"
    would result in the integer value associated with the %n being undefined.

    >And was the code you posted before supposed to work? My output from GCC did not match yours.

    It did for me with BC55; that is why I mentioned that it is broken. The first directive should have a matching failure.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #20
    FOX
    Join Date
    May 2005
    Posts
    188
    Understood... Thanks! I wonder why this wasn't in the glibc man pages for scanf on my system though...

  6. #21
    Registered User
    Join Date
    Apr 2005
    Posts
    7
    Wow, a lot replies. Thanks everyone for your support. I will try to write the code using sscanf. I hope that it will work! I will let everyone now, when it works. Thank you all.

    Kind Regards,

    Allart

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 02:04 PM
  3. Replies: 26
    Last Post: 06-15-2005, 03:38 PM
  4. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  5. Replies: 1
    Last Post: 09-30-2001, 08:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21