Update cv6/a_station.c
This commit is contained in:
		
							parent
							
								
									99ba57e056
								
							
						
					
					
						commit
						b9298b3486
					
				| @ -111,4 +111,40 @@ int count_capacity(struct station* station) { | ||||
|     return total_capacity; | ||||
| } | ||||
| 
 | ||||
| // Функція для завантаження бази даних з текстового файлу
 | ||||
| int load_from_file(struct station* station, const char* filename) { | ||||
|     FILE* file = fopen(filename, "r"); | ||||
|     if (file == NULL) { | ||||
|         return -1; // Не вдалося відкрити файл
 | ||||
|     } | ||||
| 
 | ||||
|     char target[TARGET_SIZE]; | ||||
|     int capacity; | ||||
|      | ||||
|     while (fscanf(file, "%s %d", target, &capacity) == 2) { | ||||
|         add_target_capacity(station, target, capacity); | ||||
|     } | ||||
| 
 | ||||
|     fclose(file); | ||||
|     return 0; // Успішне завантаження
 | ||||
| } | ||||
| 
 | ||||
| // Функція для збереження бази даних у текстовий файл
 | ||||
| int save_to_file(struct station* station, const char* filename) { | ||||
|     FILE* file = fopen(filename, "w"); | ||||
|     if (file == NULL) { | ||||
|         return -1; // Не вдалося відкрити файл
 | ||||
|     } | ||||
| 
 | ||||
|     for (int i = 0; i < station->track_count; i++) { | ||||
|         struct car* current = station->tracks[i]; | ||||
|         while (current != NULL) { | ||||
|             fprintf(file, "%s %d\n", current->value, current->capacity); | ||||
|             current = current->next; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     fclose(file); | ||||
|     return 0; // Успішне збереження
 | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user