Advertisement
ilia844

Untitled

Sep 22nd, 2019
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. typedef struct {
  2.     int Day, Month, Year;
  3. } Data;
  4.  
  5. typedef struct {
  6.     char Name[20], LastName[20], FatherName[20];
  7.     Data RegistrationData;
  8.     int YearOfReceipt;
  9. } Person;
  10.  
  11. int ReadFile(char* FName, Person* List) {
  12.     int i = 0;
  13.     FILE* InFile;
  14.     InFile = fopen(FName, "r");
  15.     while (fscanf(InFile, "%s %s %s", List[i].LastName, List[i].Name, List[i].FatherName) != EOF)
  16.     {
  17.         fscanf(InFile, "%d.%d.%d", &List[i].RegistrationData.Day, &List[i].RegistrationData.Month, &List[i].RegistrationData.Year);
  18.         i++;
  19.     };
  20.     fclose(InFile);
  21.     return i;
  22. }
  23.  
  24. void WriteFile(char* FName, Person* List, int Size) {
  25.     FILE* OutFile;
  26.     OutFile = fopen(FName, "w");
  27.     for (int i = 0; i < Size; i++) {
  28.         fprintf(OutFile, "%s %s %s gets new apartments in - %d year.\n", List[i].LastName, List[i].Name,
  29.             List[i].FatherName, List[i].YearOfReceipt);
  30.     }
  31.     fclose(OutFile);
  32. }
  33.  
  34.  void FindData(Person* List, int Size) {
  35.      int i = 0, CurYear = 2019;
  36.      while (i < Size)
  37.      {
  38.          if (i % 5 == 0)
  39.              CurYear++;
  40.          List[i].YearOfReceipt = CurYear;
  41.          i++;
  42.      };
  43.  }
  44.  
  45. int main() {
  46.     int i = 0;
  47.     int Size, CurYear = 2019;
  48.     char FileName[20] = "!.txt";
  49.     char OutFileName[20] = "OutFile.txt";
  50.     Person People[20];
  51.     printf("List of people who needs a new apartments: \n");
  52.     Size = ReadFile(FileName, People);
  53.     for (i = 0; i < Size; i++) {
  54.         printf("%s %s %s - %d.%d.%d\n", People[i].LastName, People[i].Name, People[i].FatherName,
  55.             People[i].RegistrationData.Day, People[i].RegistrationData.Month, People[i].RegistrationData.Year);
  56.     }
  57.     i = 0;
  58.  
  59.     FindData(People, Size);
  60.     WriteFile(OutFileName, People, Size);
  61.     printf("\nNew list:\n");
  62.     for (i = 0; i < Size; i++)
  63.     {
  64.         printf("%s %s %s gets new apartments in - %d year.\n", People[i].LastName, People[i].Name,
  65.             People[i].FatherName, People[i].YearOfReceipt);
  66.     }
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement