Advertisement
Soverein

Untitled

Jan 15th, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include<string.h>
  5. struct Student {
  6. char pib[40];
  7. int bal;
  8. };
  9.  
  10. int main()
  11. {
  12. Student znach;
  13. znach.bal = 10;
  14. strcpy(znach.pib, "Ivanov");
  15. printf("%s %d \n", znach.pib, znach.bal);
  16. fprintf(stdout,"%s %d \n", znach.pib, znach.bal);
  17. FILE* outputf;
  18. outputf = fopen("file.txt", "w");
  19. fprintf(outputf, "%s %d \n", znach.pib, znach.bal);
  20. fclose(outputf);
  21. Student znach1;
  22. outputf = fopen("file.txt", "r");
  23. if (!outputf)
  24. {
  25. printf("File not found");
  26. return 1;
  27. }
  28. fscanf(outputf, "%s%d", &(znach1.pib),&(znach1.bal));
  29. printf("%s %d \n", znach1.pib, znach1.bal);
  30. fclose(outputf);
  31.  
  32. /// ///////////////////////////////////////////////////////////////////////////////
  33.  
  34. FILE* fb;
  35. fb = fopen("f.bin", "wb");
  36. fwrite(&znach1, sizeof(znach1), 1, fb);
  37. fclose(fb);
  38. fb = fopen("f.bin", "rb");
  39. if (!fb)
  40. {
  41. printf("File not found");
  42. return 1;
  43. }
  44. Student x;
  45. fread(&x, sizeof(x), 1, fb);
  46. printf("from bin:%s %d\n", x.pib, x.bal);
  47.  
  48. fclose(fb);
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement