Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 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.         char fnm[strlen(namefile)+strlen(".bin")];
  14.         strcat(fnm,strcat(namefile,".bin"));
  15.         FILE* p = fopen(namefile, "wb+");
  16.         int status = fwrite(arr, sizeof(student_t), size, p);
  17.         fclose(p);
  18.         return status;
  19.        
  20. }
  21.  
  22. int main(int argc, char **argv)
  23. {
  24.     char str[] = "nameoffile";
  25.    student_t arr[] = { {"failure", 1234, 55.4}, {"loserp3", 4321, 80} , {"efs" , 5678, 99.9} };
  26.    if (writeStudent(arr,3,str )==3)
  27.         printf("operation successfully\n");
  28.        
  29.     getchar();
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement