i have the following structure:
Code:
typedef struct fagure
{
int celule[50];
char tip;
int regine[300];
} fagure;
and i have a file with the structure
[aray of int] [char (C or R character)] [aray of int]
... many lines
what would be a smart way to read it ?
i've done something like this:
Code:
fagure temp;
char a;
int n=0,m=0;
temp.tip=0;
while((fscanf(f,"%c",&a))!=EOF)
{
if((a!=' ')&&(a!='\n'))
{
if((a=='C')||(a=='R')) temp.tip=a;
if(temp.tip==0) temp.celule[n++]=a-'0';
if((temp.tip!=0)&&(a!='C')&&(a!='R')) temp.regine[m++]=a-'0';
}
if(a=='\n')
{
generare(temp,n,m);
temp.tip=0;
n=0;
m=0;
}
}
generare(temp,n,m);
where generare(temp,n,m) is the print function.
The only problem with this sort of read is that if i have a two digit number it separes it in do numers of one digit.
Pls help!
Thank you!