Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define SIZE 5
  4. typedef struct
  5. {
  6.     char name[SIZE];
  7.     int id;
  8.     float avg;
  9. }student_t;
  10.  
  11. int writeStudent(student_t arr[], int size, char namefile[])
  12. {
  13.         strcat(namefile,".bin");
  14.         FILE* p = fopen(namefile, "wb+");
  15.         int status = fwrite(arr, sizeof(student_t), size, p);
  16.         fclose(p);
  17.         return status;
  18.        
  19. }
  20.  
  21. int main(int argc, char **argv)
  22. {
  23.     char str[] = "nameoffile";
  24.    student_t arr[] = { {"failure", 1234, 55.4}, {"loserp3", 4321, 80} , {"efs" , 5678, 99.9} };
  25.    if (writeStudent(arr,3,str )==3)
  26.         printf("operation successfully\n");
  27.        
  28.     getchar();
  29.    
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement