Advertisement
rafikamal

Structure Writing

Feb 6th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 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", "wb")) == NULL)
  16.     {
  17.         printf("Error opening file.\n");
  18.         exit(1);
  19.     }
  20.    
  21.     scanf("%d", &in.number);
  22.     getchar();
  23.     gets(in.name);
  24.    
  25.     if(fwrite(&in, sizeof in, 1, fp) != 1)
  26.     {
  27.         printf("Error writing to file\n");
  28.         exit(2);
  29.     }
  30.    
  31.     fclose(fp);
  32.    
  33.     return 0;
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement