I'm reading a parque.txt
file that contains the hours a car was in a parking lot, type "9h00 10h30"
, this on each line.
I was trying to get these times in each char block, in which case I would have hora_i="9", min_i="00", hora_f="10", min_f="30"
, the problem is that in printf
it shows hora_i="9", min_i="009", hora_f="10009", min_f="3010009"
.
I've tried to fflush(stdin)
, but it did not work ...
void calcula_estacionamento()
{
FILE *f;
int n=0,i=0;
char linha[MAX],hora_i[2]="",min_i[2]="",hora_f[2]="",min_f[2]="";
f=fopen("parque.txt","r");
while(fgets(linha,MAX,f)!=NULL)
{
while(linha[n]!='h')
{
hora_i[i]=linha[n];
n++;
i++;
}
i=0;
n++;
while(linha[n]!=' ')
{
min_i[i]=linha[n];
n++;
i++;
}
i=0;
n++;
while(linha[n]!='h')
{
hora_f[i]=linha[n];
n++;
i++;
}
i=0;
n++;
while(linha[n]!='void calcula_estacionamento()
{
FILE *f;
int n=0,i=0;
char linha[MAX],hora_i[2]="",min_i[2]="",hora_f[2]="",min_f[2]="";
f=fopen("parque.txt","r");
while(fgets(linha,MAX,f)!=NULL)
{
while(linha[n]!='h')
{
hora_i[i]=linha[n];
n++;
i++;
}
i=0;
n++;
while(linha[n]!=' ')
{
min_i[i]=linha[n];
n++;
i++;
}
i=0;
n++;
while(linha[n]!='h')
{
hora_f[i]=linha[n];
n++;
i++;
}
i=0;
n++;
while(linha[n]!='%pre%')
{
min_f[i]=linha[n];
n++;
i++;
}
printf("\n%s %s %s %s",hora_i,min_i,hora_f,min_f);
n=0;
i=0;
}
}
')
{
min_f[i]=linha[n];
n++;
i++;
}
printf("\n%s %s %s %s",hora_i,min_i,hora_f,min_f);
n=0;
i=0;
}
}