Menu

#3 unable to handle NULL strings by fscanf

0.0.1
open
nobody
2017-11-01
2010-08-15
Anonymous
No

Originally created by: gass
Originally owned by: bert

If a tag has a empty field, fscanf emits an error and does grabs nothing.
Example $DIMLDRBLK, using fscanf (fp, "%i\n%s\n", &n, tstring);:
9
$DIMLDRBLK
1

9
$DIMLUNIT
70
2

Discussion

  • Anonymous

    Anonymous - 2010-08-16

    Originally posted by: bert

    Well, in that case "nothing" and "error" are the conditions to test for.
    Unless you mean that fscanf is the wrong tool used for this purpose because of this behaviour may lead to undefined results.
    Kind regards, Bert Timmerman.

     
  • Anonymous

    Anonymous - 2010-08-16

    Originally posted by: bert

    As an alternative we may use fgets with a maximum length of 255 chars (256 including the \n) as that is the MSDOS limit still clinging to DXF.
    In global.h we already have: #define DXF_MAX_STRING_LENGTH 255
    Quote from wikipedia:
    The fgets function terminates reading after a new-line character is found, after it reaches end-of-file, or after (length - 1) characters have been read, even if a new-line has not been reached. If a new-line was reached it is included in the string as the last character before the null character. The length argument includes space needed for the null character which will be appended to the end of the string.
    .....
    End of quote
    Kind regards, Bert Timmerman.

     
  • Anonymous

    Anonymous - 2010-08-16

    Originally posted by: gass

    there is the getline function too ... i have to read global.h to check the macros available there ... that is handy.

     
  • Anonymous

    Anonymous - 2014-12-01
     

Log in to post a comment.