我正在研究ac程序,这是我正在使用的结构
struct EngineParts{
int serial_number;
unsigned int year_of_manufacture;
unsigned int quantity;
char *material;
}*Eparts;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
`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’)`
Run Code Online (Sandbox Code Playgroud)
在这三行中
*new->quantity = quantity;
*new->serial_number = serial_number;
*new->year_of_manufacture = year_of_manufacture;
Run Code Online (Sandbox Code Playgroud)
这是完整的实现
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++;
}
Run Code Online (Sandbox Code Playgroud)
PS:我查看了以下问题,
但他们似乎没有帮助我.
有关如何解决问题的任何建议?