Advertisement
Guest User

adasd

a guest
Feb 25th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1.  
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <string>
  5. #include <cstdio>
  6.  
  7.  
  8. int main() {
  9.    
  10.     FILE* fp = fopen("notes.txt", "w+");
  11.  
  12.     setlocale(LC_ALL, ".1251");
  13.     int counter = 0;
  14.     char buf[30];
  15.     struct Note {
  16.         char surname[30] = "Aliaksandr D.Hrakovich";
  17.         char phone[20] = "+375339043057";
  18.         char birth_date[11] = { "19.11.2001" };
  19.         char zodiac[15] = "Scorpio";
  20.     };
  21.     struct Note notes[20];
  22.     struct Note tmp;
  23.     for (int i = 1; i < 5; i++) {
  24.         fwrite(&notes,sizeof(Note),1,fp);
  25.     }
  26.     printf("Surname:\t\t\t\tPhone:\t\t\t\tBirth_date:\t\t\tZodiac:\t\t\t\t\n");
  27.  
  28.     fclose(fp);
  29.     FILE* fr = fopen("notes.txt", "r");
  30.  
  31.    
  32.     while (!feof(fr)) {
  33.  
  34.         fread(&tmp, sizeof(Note), 1, fr);
  35.         printf("%s\t\t\t", tmp.surname);
  36.         printf("%s\t\t\t", tmp.phone);
  37.         printf("%s\t\t\t", tmp.birth_date);
  38.         printf("%s\n", tmp.zodiac);
  39.  
  40.  
  41.     }
  42.  
  43.     fclose(fr);
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement