I can't find the error in this function,it only writes 0's on my .txt file. It is supposed to read the scores from teams like (2 x 1) team 2 beats team 1 or (2 - 1) team 2 and 1 have a deuce. In the "seek" function,the 3 first characters of the file are "t g",in which t = teams and g = games. I've tried many approaches but none of them worked...
void calcular_resultados(char nome_campeonato[],int vitorias[50],int derrotas[50],int empates[50])
{
int retornador = 1,times=0;
FILE *arq;
FILE *resultados;
strcpy(results,nome_campeonato);
strcat(results," - Resultados.txt");
if(arq = fopen(campeonato,"r")) /* abre o arquivo de campeonato para leitura */
{
int t1,t2;
char x,barraene;
resultados = fopen(results,"w"); /* abre o arquivo de resultados para ESCRITA */
fscanf(arq,"%d",×);
rewind(arq);
for(i=0;i<times;i++)
vitorias[i] = 0;
for(i=0;i<times;i++) //Zera os valores de cada vitoria para serem incrementados
derrotas[i] = 0;
for(i=0;i<times;i++) //Zera os valores de cada derrota para serem incrementados
empates[i] = 0;
fseek(arq,3,SEEK_SET);
while(eof(campeonato) == 0)
{
printf("entrou no while\n");
int posicao;
fscanf(arq,"%d %c %d",&t1,&x,&t2); /* faz o scan de uma "partida" */
posicao = ftell(resultados);
printf("posicao atual: %d\n",posicao);
if(x == 'x')
{
vitorias[t1]++;
derrotas[t2]++;
}else if(x == '-')
{
empates[t1]++;
empates[t2]++;
}
}
fclose(resultados);
resultados = fopen(results,"w");
for(i=0;i<times;i++)
{
fprintf(resultados,"%d %d %d\n",vitorias[i],derrotas[i],empates[i]);
}
}else
{
printf(ARQUIVO_N_ENCONTRADO);
}
fclose(resultados);
fclose(arq);
}