Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define SIZE_OF_BUFFER 10
- /*
- while(!feof(stream))
- {
- ...
- }
- */
- int main (int argc, char **argv){
- FILE* fp = NULL;
- size_t size;
- char buffer[SIZE_OF_BUFFER];
- fp = fopen("example.txt", "rb");
- if(fp)
- {
- /*
- fread returns the number of objects read
- this may be less than the number requested
- feof and ferror must be used to determine status
- */
- size = fread(buffer,1,SIZE_OF_BUFFER,fp);
- if(size!=SIZE_OF_BUFFER) printf("info: size differs from SIZE_OF_BUFFER.\n");
- if(feof(fp)) printf("info: the EOF flag is set.\n");
- else printf("info: the EOF flag is not set.\n");
- if (ferror(fp))
- {
- printf("error: file read error.\n");
- clearerr(fp);
- }
- else printf("info: there is no read error.\n");
- fclose(fp);
- }
- else printf("error: can't open file.\n");
- return 0;
- }
Add Comment
Please, Sign In to add comment