I’m working on a c program and here is the structure I am using
struct EngineParts{
int serial_number;
unsigned int year_of_manufacture;
unsigned int quantity;
char *material;
}*Eparts;
And I am getting the following error
`Automobile.c:79:5: error: invalid type argument of unary ‘*’ (have ‘unsigned int’)`
`Automobile.c:80:5: error: invalid type argument of unary ‘*’ (have ‘int’)`
`Automobile.c:81:5: error: invalid type argument of unary ‘*’ (have ‘unsigned int’)`
in these three lines
*new->quantity = quantity;
*new->serial_number = serial_number;
*new->year_of_manufacture = year_of_manufacture;
Here is the complete implementation
void automobile_add_part(const int serial_number,
const unsigned int year_of_manufacture,
const unsigned int quantity ,
const char *material){
/*
* Store the address to the latest part
*/
struct EngineParts *new ;
new = (Eparts+available_number_of_parts);
// Copying a String is a little bit complicated
// First memory is allocated for the string
*new->material = (char *)calloc(strlen(material),sizeof(char));
//Then the string is copied
strcpy((char *)*new->material,material);
*new->quantity = quantity;
*new->serial_number = serial_number;
*new->year_of_manufacture = year_of_manufacture;
available_number_of_parts++;
}
PS :
I have checked out the following questions ,
error: invalid type argument of ‘unary *’ (have ‘int’)
Invalid type argument of -> C structs
but they don’t seem to help me.
Any suggestions on how to solve the problem ?
Do it this way:
The extra pointer dereference (
*new->quantity) is an error:new->quantityis anint, not any kind of pointer so the compiler complains.Dereferencing the
newpointer (is it even legal to have a variable named such?) is already done throughoperator->.