Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct {
- int Day, Month, Year;
- } Data;
- typedef struct {
- char Name[20], LastName[20], FatherName[20];
- Data RegistrationData;
- int YearOfReceipt;
- } Person;
- int ReadFile(char* FName, Person* List) {
- int i = 0;
- FILE* InFile;
- InFile = fopen(FName, "r");
- while (fscanf(InFile, "%s %s %s", List[i].LastName, List[i].Name, List[i].FatherName) != EOF)
- {
- fscanf(InFile, "%d.%d.%d", &List[i].RegistrationData.Day, &List[i].RegistrationData.Month, &List[i].RegistrationData.Year);
- i++;
- };
- fclose(InFile);
- return i;
- }
- void WriteFile(char* FName, Person* List, int Size) {
- FILE* OutFile;
- OutFile = fopen(FName, "w");
- for (int i = 0; i < Size; i++) {
- fprintf(OutFile, "%s %s %s gets new apartments in - %d year.\n", List[i].LastName, List[i].Name,
- List[i].FatherName, List[i].YearOfReceipt);
- }
- fclose(OutFile);
- }
- void FindData(Person* List, int Size) {
- int i = 0, CurYear = 2019;
- while (i < Size)
- {
- if (i % 5 == 0)
- CurYear++;
- List[i].YearOfReceipt = CurYear;
- i++;
- };
- }
- int main() {
- int i = 0;
- int Size, CurYear = 2019;
- char FileName[20] = "!.txt";
- char OutFileName[20] = "OutFile.txt";
- Person People[20];
- printf("List of people who needs a new apartments: \n");
- Size = ReadFile(FileName, People);
- for (i = 0; i < Size; i++) {
- printf("%s %s %s - %d.%d.%d\n", People[i].LastName, People[i].Name, People[i].FatherName,
- People[i].RegistrationData.Day, People[i].RegistrationData.Month, People[i].RegistrationData.Year);
- }
- i = 0;
- FindData(People, Size);
- WriteFile(OutFileName, People, Size);
- printf("\nNew list:\n");
- for (i = 0; i < Size; i++)
- {
- printf("%s %s %s gets new apartments in - %d year.\n", People[i].LastName, People[i].Name,
- People[i].FatherName, People[i].YearOfReceipt);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement