Write list in binary file

4

The idea of this method is to write all words from a list of nodes in a binary file. I have a linked list of nodes, where each node has two information, its information, and a reference to the next node in the list. The idea is to write the information of each node in a binary file. However, I'm getting the following error:

warning: incompatible pointer to integer conversion assigning       to 'char' from 'const char *'

What happens in this line of code:

*pal = nodo->info;

I just do not understand what the problem is, since my structure defines the node information as a pointer as well. The following is the NODO framework code and the

typedef struct Temp{
    char const *info;
    struct Temp *prox;
}TNODOPAL;

Method:

void escreveBinario(){

    TNODOPAL *nodo = inicioPal;

    FILE *fp;
    char *pal = NULL;

    fp = fopen( "binary.dat" , "wb" );

    if (fp == NULL) // Se não conseguiu criar
    {
        printf("Problemas na CRIACAO do arquivo\n");
        return;
    }

    while(nodo != NULL){
        *pal = nodo->info;
        fwrite (&pal, sizeof(char) * 30, 200, fp);
        nodo = nodo->prox;
    }
    fclose(fp);

}
    
asked by anonymous 26.11.2015 / 11:51

1 answer

3

pal is a pointer to char so *pal will be a memory location containing char . When você faz * pal = c você está armazenando um char na posição de memória apontada pelo ponteiro pal '.

I think what you wanted to do is

pal = nodo->info
fwrite (pal, sizeof(char) * 30, 200, fp);

Or simply

fwrite (nodo->info, sizeof(char) * 30, 200, fp);
    
26.11.2015 / 14:33