0
I’m having trouble with an Info capture function of a file with the fseek() function [I don’t know if there is a better alternative...]. Getting back to the problem, I want to read a file that has:
" 2165327575 R" "7625621 W" and so on...
And store that number in a var int and the letter in a char and send them for treatment in another function.
But I’m doing something wrong, but I don’t know what it is!
The code:
VETOR_CACHE TrataCache(VETOR_CACHE cache, CACHEDESC descricao, int *access_count, int *read_hits, int *read_misses, int *write_hits, int *write_misses)
{
int endereco, i=0;
char endereco_aux[100];
char op,ch;
FILE *arq;
arq = fopen("input.dat", "r");
if(arq == NULL)
printf("Erro, nao foi possivel abrir o arquivo\n");
else
{
printf("Entrou aqui 1\n");
while( (ch=fgetc(arq))!= EOF )
{
fseek(arq,1,SEEK_SET);
printf("Entrou aqui 2\n");
while( (ch=fgetc(arq))!= 'R' || (ch=fgetc(arq))!= 'W' || (ch=fgetc(arq))!= '\n')
{
printf("Entrou aqui while\n");
endereco_aux[i] = ch;
//printf("%s\n", endereco_aux);
i++;
}
printf("Saiu while\n"); //Não saiu ainda...
i=0;
fseek(arq, 0,SEEK_CUR); //aqui ta errado eu acho
if((ch=fgetc(arq))== 'R' || (ch=fgetc(arq))== 'W') //aqui ta errado ... quero percorrer e gravar os W/R
op = ch;
if( (ch=fgetc(arq))!= EOF )
{
endereco = atoi(endereco_aux);
//A IDEIA É CHEGAR AQUI COM O OP E O ENDERECO E MANDAR PRA OUTRA FUNÇÃO TRATAR...
printf("%d\n", endereco);
printf("%s\n", op);
*access_count = ContaLinhas();
cache = OperaCache(true , endereco, op, cache, descricao, read_hits, read_misses, write_hits, write_misses);
}
}
}
fclose(arq);
return cache;
}
I used these 'printf()' to base where the error occurred in the execution...
Yes, I looked for another alternative and found a standardized fscanf that worked... That’s what you said, thanks.
– Oberdan Santos