Advertisement
rafikamal

Structure Read

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