0
votes

let say I have this struct

 struct person {
   char last_name [10];
 };
typedef struct person Person;

And I fill this struct-object with a certain name

Person p;
Person *ptrPerson = &p;
strcpy(ptrPerson->last_name, "Johnson"); 

And then I put this name in an array of type Person ... put in the first position

Person queue[10];
queue[0] = *ptrPerson;

So far so good. But how do I nullify the arraypostion after that - or at least put a character "-" there instead:

queue[0].last_name = "-";

I get the following compilation error:

error: incompatible types when assigning to type 'char[10]' from type 'int'

2
Where is declared variable first_name ?Martin Perry
first_name is not a member of Persondigital_revenant

2 Answers

2
votes

queue[0].last_name = "-"; is trying to assign the address returned by "-".

Use strcpy (queue[0].last_name ,"-");

1
votes

Either keep track of which entries are used and which are "free". Or if you want to clear the whole structure you can use e.g. memset. Or to copy a string you already are using strcpy at one place, why don't you use it at the other?