Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MyString_Status mystring_input(MYSTRING hString,
- FILE * hFile,
- int bIgnoreLeadingWhiteSpace,
- int (*fTerminate)(char ch, int * pbDiscardChar)) {
- char ch = '\0';
- int eofCheck = 0;
- int t, discard;
- mystring_truncate(hString, 0);
- if(hFile == NULL) return MYSTRING_STATUS_ERROR;
- eofCheck = fscanf(hFile, "%c", &ch);
- // If bIgnoreWhiteSpace is true, gobble leading whitespace.
- if(bIgnoreLeadingWhiteSpace) {
- while(isspace(ch)) {
- eofCheck = fscanf(hFile, "%c", &ch);
- if(eofCheck == EOF) return MYSTRING_STATUS_ERROR;
- }
- }
- // Add all valid characters to the string, overwriting the old string.
- while(eofCheck != EOF) {
- t = fTerminate(ch, &discard);
- if(discard == 0) mystring_push(hString, ch);
- if(t) return MYSTRING_STATUS_SUCCESS;
- eofCheck = fscanf(hFile, "%c", &ch);
- }
- if(eofCheck == EOF) return MYSTRING_STATUS_ERROR;
- return MYSTRING_STATUS_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement