Ir para conteúdo
Fórum Script Brasil

Luiz.Sabbagh

Membros
  • Total de itens

    2
  • Registro em

  • Última visita

Sobre Luiz.Sabbagh

Luiz.Sabbagh's Achievements

0

Reputação

  1. Boa noite, Estou tendo problemas com a leitura de dados em um arquivo binário. Ele lê normalmente na primeira parte, que descobre o número de times no arquivo. Então, eu precisaria salvar os dados desse time nesse arquivo, mas onde faz a alocação ele não lê o arquivo (fiz só um teste para ver se entra no if, mas nada) Se puderem me ajudar, agradeço! typedef struct { char nome[TAM_NOME]; //0 goleiro, 1 zagueiro, 2 lateral, 3 volante, 4 meio, 5 atacante unsigned int posicao; unsigned int gols_marcados; unsigned int bolas_roubadas; unsigned int numero_jogos; unsigned int finalizoes_certas; unsigned int finalizoes_erradas; unsigned int faltas_recebidas; unsigned int faltas_cometidas; unsigned int cartoes_vermelhos; unsigned int cartoes_amarelos; unsigned int penalti_defendidos; unsigned int defesas; } jogador_t; typedef struct { char nome[TAM_NOME]; char estado[3]; unsigned int dia_fundacao; unsigned int mes_fundacao; unsigned int ano_fundacao; unsigned int numero_tit_brasileiros; unsigned int numero_copas_brasil; unsigned int numero_tit_libertadores; unsigned int numero_tit_estadual; jogador_t jogadores[NUM_JOGADORES]; } times_t; times_t *le_times(const char *arquivo, unsigned int *numero_de_times){ int i, j, teste, temp, testa, x; FILE *ptr; ptr=abre_arquivo("arq.dat"); rewind(ptr); times_t descobre; //descobre o numero de times no arquivo for (i=1; i>=0; i++){ teste = fread(&descobre,sizeof(descobre),1, ptr); if (teste != 1){ temp = i-1; break; } } //aloca memoria e le o numero de times - TÁ DANDO PAU AQUI times_t *le = (times_t *) malloc(sizeof(times_t)); testa = fread(&le[0], sizeof(times_t), 1, ptr); printf("%i\n", testa); for (j=1; j<temp; j++){ le = (times_t *) realloc(le, (j+1)*sizeof(times_t) ); testa = fread(&le[j], sizeof(times_t), 1, ptr); if(testa != 0){ printf("Teste\n"); } } return temp; }
×
×
  • Criar Novo...