usaa21/cv2/program.c

50 lines
1.0 KiB
C
Raw Normal View History

2021-10-12 17:20:19 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define LINESIZE 100
struct Pizza {
char name[LINESIZE];
float prize;
};
int main() {
char line[LINESIZE];
memset(line, 0, LINESIZE);
char name[LINESIZE];
struct Pizza jedalny_listok[LINESIZE];
memset(jedalny_listok, 0, sizeof(struct Pizza) * LINESIZE);
size_t velkost;
2021-10-12 18:34:11 +00:00
int a = 0;
int i = 0;
float cena;
2021-10-12 17:20:19 +00:00
while (fgets(line, LINESIZE, stdin)) {
velkost = strlen(line);
if (velkost == 1 && line[velkost - 1] == '\n') {
break;
}
2021-10-12 18:34:11 +00:00
if (i == 0) {
strcpy(jedalny_listok[a].name, line);
2021-10-12 17:20:19 +00:00
2021-10-12 18:34:11 +00:00
i++;
a++;
}
else if (i == 1){
cena = atof(line);
jedalny_listok[a].prize = cena;
2021-10-12 17:20:19 +00:00
2021-10-12 18:34:11 +00:00
i--;
a++;
}
}
for (i = 0; i<a; i++){
if (i == 0 || i % 2 == 0) {
printf("%s", jedalny_listok[i].name);
}
else {
printf("%f\n", jedalny_listok[i].prize);
}
2021-10-12 17:20:19 +00:00
}
return 0;
}