Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define SIZE 5
- typedef struct
- {
- char name[SIZE];
- int id;
- float avg;
- }student_t;
- int writeStudent(student_t arr[], int size, char namefile[])
- {
- char fnm[strlen(namefile)+strlen(".bin")];
- strcat(fnm,strcat(namefile,".bin"));
- FILE* p = fopen(namefile, "wb+");
- int status = fwrite(arr, sizeof(student_t), size, p);
- fclose(p);
- return status;
- }
- int main(int argc, char **argv)
- {
- char str[] = "nameoffile";
- student_t arr[] = { {"failure", 1234, 55.4}, {"loserp3", 4321, 80} , {"efs" , 5678, 99.9} };
- if (writeStudent(arr,3,str )==3)
- printf("operation successfully\n");
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement