#include <stdio.h>
|
void
clearerr (FILE *stream); |
int
feof (FILE *stream); |
int
ferror (FILE *stream); |
int
fileno (FILE *stream); |
The function feof tests the end-of-file indicator for the stream pointed to by stream, returning non-zero if it is set. The end-of-file indicator can only be cleared by the function clearerr.
The function ferror tests the error indicator for the stream pointed to by stream, returning non-zero if it is set. The error indicator can only be reset by the clearerr function.
The function fileno examines the argument stream and returns its integer descriptor.
/****************** this program shows finding error set using ferror **************/ /****************** and clearing it using clearerr functions ***********************/ #include <stdio.h> int main() { char a; FILE* fp = fopen("c:\nput.txt", "w"); fprintf(fp, "%s", "abcdefghijklmn"); fprintf(fp, "%c", '\n'); fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn"); fclose(fp); fp=fopen("c:\nput.txt","r"); if (fp == NULL) { printf("fopen failed\n"); return -1; } else { fwrite(&a, sizeof(char), 1, fp); if (ferror (fp)) printf("error set in file stream\n"); else { fclose(fp); return -1; } clearerr(fp); if (!ferror(fp)) printf("error cleared in file stream\n"); else printf("error still unexpected set in file stream\n"); fclose (fp); } return 0; }
Output
error set in file stream error cleared in file stream
© 2005-2007 Nokia |