Caute, snazim sa napisat kod v jazyku C, ktory bude citat zo suboru (v subore je ulozene meno a za nim vek na jednom riadku a potom pokracuju riadky v tomto style) meno a vek osoby a ulozi to do statickeho pola struktur. Problem mam stym, ze ak chcem vypisat, neskor nejaku osobu zo struktury tak mi vypisse len poslednu a to len na 0 indexe. K ostatnym neviem pristupit. Viete mi poradit, kde robim chybu ?
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define MAX 81
#define COUNT 1000
typedef struct {
char name[MAX];
int old;
} PERSON;
int main(void){
FILE *fr;
PERSON array[COUNT];
char file[MAX];
int i;
printf("Enter the name file\n");
scanf(" %[^\n]s", file);
if ((fr = fopen(file, "r")) == NULL){
printf("Couldn't the open %s file\n", file);
exit(1);
}
int o, t, j = 0;
int lok = 0;
for (o = 0; o < COUNT; o++){
while (fscanf(fr, "%s %d", array[o].name, &array[o].old) != EOF){
printf("%s %d\n", array[o].name, array[o].old);
j++;
}
}
printf("Printout the first person and age: %s %d\n", array[0].name, array[0].old);
/*
for (t = 0; t < j; t++){
lok += pole[o].stari;
}
*/
/*
printf("Pocet precitanych cisel bol: %d\n", j);
printf("Sucet precitanych cisel bol: %d\n", lok);
*/
if ((fclose(fr)) == EOF){
printf("Couldn't the close file\n");
}
return 0;
}