Hi,
I need to transfer data from file to fields... Can anyone help me?
file:
name surname weight age male/female
name surname weight age male/female
marek mixa 70 23 M
...
kód:
typedef struct lidi
{
char cl_jmeno[16], cl_prijmeni[21], cl_muz_zena[1],cl_vyska[3], cl_vaha[3];
} LIDI;
LIDI lidi[6];
i know that i have it only by char, but if i will do it in integer, im also not able to do it
int nacti_lidi()
{
int i, j,lokace,cislo,;
char c;
printf("obsah souboru:\n");
for(i=0; i<2;i++) //dva radky
{
lokace = 1;
cislo = -1;
for(j=0; j<60; j++) //omezeni radku
{
c = getc(zdrojovysoubor);
if(c == '\n'){
printf("\n"); //vypisem obsah souboru
break;
}else{
if(c == ' '){
lokace ++; //udava co plnime za pole
printf(" ");
cislo = -1; //udava cislo v poli od nuly
continue;
}
cislo ++;
printf("%c", c ); //vypisem obsah souboru
if(lokace == 1){
lidi[i].cl_jmeno[cislo] = c;
}
else if(lokace == 2){
lidi[i].cl_prijmeni[cislo] = c;
}
else if(lokace == 3){
lidi[i].cl_vyska[cislo] = c;
}
else if(lokace == 4){
lidi[i].cl_vaha[cislo] = c;
}
else if(lokace == 5){
lidi[i].cl_muz_zena[cislo] = c;
}
}
}
}
printf("\n***********************************\n");
}
I think that right way is atoi() but Im not able to finish that... Can anyone help me? Thanks