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
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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.
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.