Error: incompatible types when assigning to type 'char [200]' from type 'char'

1

When I try to insert char motorista , an error appears:

  

[Error] Incompatible types when assigning to type 'char [200]' from   type 'char'

Code:

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

typedef struct caminhoes{
    int id;
    char motorista[200];
    char marca[200];
    char la[200];
    char lisd[200];
    float kml;
    struct caminhoes *prox;
}lcam;


void inserir(lcam **cabeca);
void listar (lcam *cabeca);

int main()
{
    lcam *cabeca = NULL;        
    lcam *noatual;     

    int op;

    printf("0 - Fechar \n");
    printf("1 - Cadastrar Caminhão \n");
    printf("2 - Cadastrar Carga \n");
    printf("3 - Cadastrar Cidade \n");
    printf("4 - Imprimir \n" );
    printf("5 - Excluir \n");
    printf("6 - Salvar Arquivo \n");
    printf("6 - Relatórios \n");

    printf("Digite uma opcao: \n");
    scanf("%d", &op);

    while(op!=0){
    switch(op){
            case 0:{
                op=0;
                break;
             }
             break;
            case 1: cad_cam(&cabeca);
                    break;
            case 2: (cabeca);
                    break;
            case 3: 
                    break;  
            case 4: 
                    break;
            case 5:         
                    break;
            case 6:
                   break;
        }
    printf("0 - Fechar \n");
    printf("1 - Cadastrar Caminhão \n");
    printf("2 - Cadastrar Carga \n");
    printf("3 - Cadastrar Cidade \n");
    printf("4 - Imprimir \n" );
    printf("5 - Excluir \n");
    printf("6 - Relatórios \n");

    printf("Digite uma opcao: \n");
    scanf("%d", &op);
    } 

    noatual = cabeca;
    while (noatual != NULL)
    {
        cabeca = noatual->prox;
        free(noatual);
        noatual = cabeca;
    }
}


void listar (lcam *noatual)
{
    while( noatual != NULL)    
    {
        printf("ID:%d\n",noatual->id);
        printf("Motorista:%s\n", noatual->motorista;)
        printf("KM/L:%.2f\n", noatual->kml);
        noatual = noatual->prox;    
    }
}



void inserir (lcam **cabeca)
{
    lcam *noatual, *novono;
    int id;
    float km;
    char mot;
    printf("ID:\n");
    scanf("%d", &id);
    printf("Motorista:\n");
    scanf("%s", &mot);
    printf("KM/L:\n");
    scanf("%f", &km);
    if (*cabeca == NULL)   
    {

        (*cabeca) = malloc(sizeof(lcam));
        (*cabeca)->id = id;
        (*cabeca)->motorista = mot;
        (*cabeca)->kml = km;
        (*cabeca)->prox = NULL;
    }
    else
    {
        noatual = *cabeca;
        while(noatual->prox != NULL)
            noatual = noatual->prox;    
        novono =  malloc(sizeof(lcam));
        novono->id = id;
        novono->kml = km;
        novono->prox = NULL;
        noatual->prox = novono;  
    }
}
    
asked by anonymous 03.03.2017 / 15:24

1 answer

2

You have to change this line to transform into a string :

char mot[200];

And then you have to copy to the structure in the correct way:

strcpy((*cabeca)->motorista, mot);

You may have other similar issues.

    
03.03.2017 / 15:37