usaa21/cv2/program.c

50 lines
1.0 KiB
C

#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;
int a = 0;
int i = 0;
float cena;
while (fgets(line, LINESIZE, stdin)) {
velkost = strlen(line);
if (velkost == 1 && line[velkost - 1] == '\n') {
break;
}
if (i == 0) {
strcpy(jedalny_listok[a].name, line);
i++;
a++;
}
else if (i == 1){
cena = atof(line);
jedalny_listok[a].prize = cena;
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);
}
}
return 0;
}