Update du3/program.c
This commit is contained in:
parent
a9c8b2bc84
commit
9770be8838
@ -9,19 +9,20 @@ struct listok {
|
|||||||
float cena;
|
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) {
|
if (fgets(p[*n].nazov, 101, stdin) == NULL) {
|
||||||
exit(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
p[*n].nazov[strcspn(p[*n].nazov, "\n")] = 0;
|
p[*n].nazov[strcspn(p[*n].nazov, "\n")] = 0;
|
||||||
|
|
||||||
if (scanf("%f", &p[*n].cena) != 1) {
|
if (scanf("%f", &p[*n].cena) != 1) {
|
||||||
exit(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
getchar();
|
getchar();
|
||||||
*n = *n + 1;
|
*n = *n + 1;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int compare(struct listok *a, struct listok *b) {
|
int compare(struct listok *a, struct listok *b) {
|
||||||
@ -57,8 +58,7 @@ int main(){
|
|||||||
struct listok p[LIST_SIZE];
|
struct listok p[LIST_SIZE];
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
while (1){
|
while (add_listok(p, &n)) {
|
||||||
add_listok(p, &n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sort_listok(p, n);
|
sort_listok(p, n);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user