struct atleta {
int id;
char nation[3];
char cognome[20];
char nome[20];
struct atleta *next;
};
struct atleta *creaLista2(void)
{
struct atleta *p, *paus;
struct atleta atleti;
int num = 0;
fp_atl = fopen("atleti.txt", "r");
//reading from the file
fscanf(fp_atl,"%d\n", &num);
fscanf(fp_atl,"%d ", &atleti.id);
fscanf(fp_atl,"%s ", atleti.nation);
fscanf(fp_atl,"%s ", atleti.cognome);
fscanf(fp_atl,"%s \n", atleti.nome);
// end reading
if(atleti.id==0)
p = NULL;
else
{
p = (struct atleta *)malloc(sizeof(struct atleta));
p->id = atleti.id;
strcpy(p->nation, atleti.nation);
strcpy(p->cognome, atleti.cognome);
strcpy(p->nome, atleti.nome);
// other code to create the complete list
}
the file atleti.txt is:
2
5 ITA VOLTA ALESSANDRO
7 ENG TURING ALAN
i have to load the second and the third line...
but the out is :
5 ITAVOLTA VOLTA ALESSANDRO --> 7 ENGTURING TURING ALAN
why the program load in the list ITAVOLTA and not ITA?
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire