Advertisement
rafikamal

fread

Feb 6th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {  
  6.     int a[5], i;
  7.     FILE *fp;
  8.    
  9.     if((fp = fopen("input.txt", "rb")) == NULL)
  10.     {
  11.         printf("Error opening file.\n");
  12.         exit(1);
  13.     }
  14.    
  15.     if(fread(a, sizeof a, 1, fp) != 1)
  16.     {
  17.         printf("Error reading file\n");
  18.         exit(2);
  19.     }
  20.    
  21.     fclose(fp);
  22.    
  23.     for(i = 0; i < 5; i++)
  24.         printf("%d\n", a[i]);
  25.    
  26.     return 0;
  27.    
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement