Обновить cv1/program.c
This commit is contained in:
		
							parent
							
								
									3eb785a320
								
							
						
					
					
						commit
						48b5aeb747
					
				| @ -29,22 +29,28 @@ int main() { | ||||
|     int count = 0;  | ||||
| 
 | ||||
|     printf("Zadaj hladanu surovinu: "); | ||||
|     fgets(ingredient, MAX_NAME_LEN, stdin); | ||||
|     if (fgets(ingredient, MAX_NAME_LEN, stdin) == NULL) { | ||||
|         fprintf(stderr, "Ошибка чтения ингредиента.\n"); | ||||
|         return 1; // Обработка ошибки
 | ||||
|     } | ||||
|     ingredient[strcspn(ingredient, "\n")] = '\0';  | ||||
| 
 | ||||
|     printf("Zadaj jedalny listok:\n"); | ||||
|     while (1) { | ||||
|         char name[MAX_NAME_LEN], price[MAX_NAME_LEN]; | ||||
|          | ||||
|         fgets(name, MAX_NAME_LEN, stdin); | ||||
|         if (fgets(name, MAX_NAME_LEN, stdin) == NULL) { | ||||
|             return 0; // Обработка ошибки
 | ||||
|         } | ||||
|         name[strcspn(name, "\n")] = '\0';  | ||||
|          | ||||
|         if (strlen(name) == 0) { | ||||
|             break; | ||||
|         } | ||||
|          | ||||
|         // Ввод цены
 | ||||
|         fgets(price, MAX_NAME_LEN, stdin); | ||||
|         if (fgets(price, MAX_NAME_LEN, stdin) == NULL) { | ||||
|             return 0; // Обработка ошибки
 | ||||
|         } | ||||
|         price[strcspn(price, "\n")] = '\0';  | ||||
| 
 | ||||
|         // Использование strncpy для безопасности
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user