Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PERGUNTAS val;
- lista_perguntas * aux = original->next;
- lista_perguntas * base = original;
- lista_perguntas * novo;
- while (aux != NULL) { // eu estava com um problema anteriormente que o primeiro elemento da lista era ignorado por isso eu pesquisei e encontrei esta solução que basicamente ignora esse elemento e passa para o segundo pelo que eu percebi
- aux = aux->next;
- base = base->next;
- }
- while(fread(&val, sizeof(PERGUNTAS), 1, fp)!=-1){
- novo = (lista_perguntas*) malloc(sizeof (lista_perguntas));
- novo->valor = val;
- novo->next = aux;
- base->next = novo;
- }
- #define PERGUNTA_TAM_MAX (256)
- typedef struct pergunta_s pergunta_t;
- struct pergunta_s
- {
- char pergunta[ PERGUNTA_TAM_MAX + 1 ];
- pergunta_t * prox;
- };
- int perguntas_carregar( const char * arq, pergunta_t ** perg )
- {
- FILE * pf = NULL;
- pergunta_t * p = NULL;
- pergunta_t * pant = NULL;
- pergunta_t * pprim = NULL;
- int n = 0;
- int nread = 0;
- pf = fopen( arq, "rb" );
- if(!pf)
- return ERRO_LEITURA_ARQUIVO;
- while(1)
- {
- p = malloc( sizeof(pergunta_t) );
- nread = fread( p, sizeof(pergunta_t), 1, pf );
- if( nread != 1 )
- {
- free(p);
- break;
- }
- p->prox = NULL;
- if(pant)
- pant->prox = p;
- else
- pprim = p;
- pant = p;
- n++;
- }
- fclose(pf);
- *perg = pprim;
- return n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement