usaa24/cv1/program.c
Bohdan Kapliuk fc4437c6bd cv1
2024-09-30 21:44:13 +03:00

71 lines
1.9 KiB
C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define LINESIZE 100
struct pizza {
char price[LINESIZE];
char name[LINESIZE];
};
int main(){
char surovina[LINESIZE];
char vstup[LINESIZE];
struct pizza menu[LINESIZE];
struct pizza menu1[LINESIZE];
char numbers[] = "0123456789";
char letters[] = "oizeasbtbq";
printf("Zadaj hladanu surovinu:\n");
fgets(surovina,LINESIZE,stdin);
surovina[strcspn(surovina, "\n")] = '\0';
printf("Zadaj jedalny listok:\n");
int count = 0;
while (count < LINESIZE) {
if (fgets(vstup, LINESIZE, stdin)) {
vstup[strcspn(vstup, "\n")] = '\0';
if (strlen(vstup) == 0) {
break;
}
strcpy(menu[count].name, vstup);
strcpy(menu1[count].name, vstup);
} else {
break;
}
if (fgets(vstup, LINESIZE, stdin)) {
vstup[strcspn(vstup, "\n")] = '\0';
if (strlen(vstup) == 0) {
break;
}
strcpy(menu[count].price, vstup);
strcpy(menu1[count].price, vstup);
} else {
break;
}
count++;
}
for(int i = 0; i < count;i++){
for(int j = 0; j <= strlen(menu[i].name);j++){
for(int x = 0; x <= 11;x++){
if(menu[i].name[j] == numbers[x]){
menu[i].name[j] = letters[x];
}
if(isupper(menu[i].name[j])){
menu[i].name[j] = tolower(menu[i].name[j]);
}
}
}
}
char *istr;
for(int i = 0; i <= count;i++){
istr = strstr(menu[i].name, surovina);
if(istr != NULL){
printf("%s\n", menu1[i].name);
float number = strtof(menu1[i].price, NULL);
printf("%.2f\n", number);
}
}
printf("Nacitanych %d poloziek.\n", count);
return 0;
}