Update du3/program.c

This commit is contained in:
Denis Landa 2025-10-16 17:07:29 +00:00
parent a9c8b2bc84
commit 9770be8838

View File

@ -9,19 +9,20 @@ struct listok {
float cena;
};
void add_listok(struct listok *p, int *n){
int add_listok(struct listok *p, int *n) {
if (fgets(p[*n].nazov, 101, stdin) == NULL) {
exit(0);
return 0;
}
p[*n].nazov[strcspn(p[*n].nazov, "\n")] = 0;
if (scanf("%f", &p[*n].cena) != 1) {
exit(0);
return 0;
}
getchar();
*n = *n + 1;
return 1;
}
int compare(struct listok *a, struct listok *b) {
@ -57,8 +58,7 @@ int main(){
struct listok p[LIST_SIZE];
int n = 0;
while (1){
add_listok(p, &n);
while (add_listok(p, &n)) {
}
sort_listok(p, n);