Advertisement
Kofa_Joh

Class_Work_19.04_

Apr 19th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <locale.h>
  5. #include <stdbool.h>
  6.  
  7. #define FILE_SIZE 170
  8. #define STRING_SIZE 50
  9.  
  10. struct FIO
  11. {
  12.     char FirstName[53];
  13.     int k;
  14.     char LastName[58];
  15.     char MiddleName[50];
  16.     bool b;
  17. };
  18.  
  19. enum StringPositions
  20. {
  21.     FirstNamePosition = 0,
  22.     LastNamePosition = 57,
  23.     MiddleNamePosition = 119,
  24. };
  25.  
  26. void writeString(char* string, int offset,
  27.     FILE* f)
  28. {
  29.     fseek(f, offset, SEEK_SET);
  30.     fwrite(string, STRING_SIZE, 1, f);
  31. }
  32.  
  33. void readString(char* string, int offset,
  34.     FILE* f)
  35. {
  36.     fseek(f, offset, SEEK_SET);
  37.     fread(string, STRING_SIZE, 1, f);
  38. }
  39.  
  40. int main()
  41. {
  42.     setlocale(LC_ALL, "rus");
  43.     FILE* f = fopen("d:\\t.bin", "wb");
  44.  
  45.     /*double pi = 3.14;
  46.     fwrite(&pi, sizeof(double), 1, f);
  47.     long long n = 2378462378;
  48.     fwrite(&n, sizeof(long long), 1, f);*/
  49.    
  50.     struct FIO fio = { "Vasya", 678, "Pupkin",
  51.         "Vasilyevich", true };
  52.     fwrite(&fio, sizeof(struct FIO),
  53.         1, f);
  54.  
  55.     fclose(f);
  56.     ///////////////////
  57.  
  58.     f = fopen("d:\\t.bin", "rb");
  59.  
  60.     /*double pi2;
  61.     fread(&pi2, sizeof(double), 1, f);
  62.     long long n2;
  63.     fread(&n2, sizeof(long long), 1, f);*/
  64.  
  65.     struct FIO fio2;
  66.     fread(&fio2, sizeof(struct FIO),
  67.         1, f);
  68.  
  69.     printf("%s\n", fio2.FirstName);
  70.     printf("%s\n", fio2.LastName);
  71.     printf("%s\n", fio2.MiddleName);
  72.     printf("%i\n", fio2.k);
  73.     printf("%i\n", fio2.b);
  74.  
  75.     fclose(f);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement