programming.nbk: Home | Index | Next Page: Code: SetDlgItemFloat | Previous Page: Code: float_edit_subclass
Read one line from the specified file. The newline char is discarded. If the line is empty (CR or LF only), it is discarded and the next line gotten.
Returns 0 on failure, 1 on success.
This may leave a dangling CR or LF as the first character to be read next time. That's why it ignores empty lines.
//############################################################################## // read one line from the specified file. the newline char is discarded // return 0 on failure, 1 on success //############################################################################## int readline(FILE *file, char *line, int max) { int i = 0; while(i < max - 1) { char result = fgetc(file); if (feof(file) || ferror(file)) return (0); if (i == 0 && result == '\n') continue; if (i == 0 && result == '\r') continue; if (result == '\n') break; if (result == '\r') break; line[i++] = result; } line[i] = '\0'; return (1); }
programming.nbk: Home | Index | Next Page: Code: SetDlgItemFloat | Previous Page: Code: float_edit_subclass
Notebook exported on Monday, 7 July 2008, 18:56:06 PM Eastern Daylight Time