I have this struct:

typedef struct empresa {
    char nome_empresa [20];
    MORADA morada_empresa;
    int nif;
    int telefone;
    int anocriacao;
    char cae [20];
    ESTAGIARIO estagiarios [MAX_EST];
    int num_est;

And an array of this struct:

EMPRESA empresas [MAX_EMP];

My problem is that when i try to, manually assign values to the struct variables i get an error, this is how i do it:

empresas[i].nome_empresa = "a string";

The error i get is:

"incompatibel types in assignment"

I can't figure out what is causing this. Can anyone help, please?

An array is in fact a constant pointer pointing to a block of memory.
char message [] = { 'H', 'e', 'l', 'l', 'o', '\0' };
char message [] = "Hello";
is valid : initialisation

message = { 'H', 'e', 'l', 'l', 'o', '\0' };
message = "Hello";
or even
message [] = "Hello";
is not valid : assignment

Use the string class, life will be much easier.

Try this instead:

//empresas[i].nome_empresa = "a string";
strcpy( empresas[i].nome_empresa, "a string" );

Thanks, that solved the problem :)
I get what i did wrong, now.

no real good re-assignment unless you write one yourself, which is usually what we do, thats why operator overloading is so flexible, it makes those pitfalls disappear completely.

This question has already been answered. Start a new discussion instead.