我想在函数参数中传递结构作为指针。这里是我的代码传递结构作为指针
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
typedef struct {
int yearOfManufacture;
char model[50];
bool gasoline;
} Car;
void PrintCarDetails(Car details);
int main (int argc, const char * argv[])
{
Car ford;
ford.yearOfManufacture = 1997;
ford.gasoline = true;
strcpy(ford.model, "Focus");
PrintCarDetails(&ford);
return 0;
}
void PrintCarDetails(Car *details)
{
printf("Car model %s", details->model);
}
我得到一个错误“路过的汽车不兼容型轿车的参数我错过了什么
提示:函数定义也可用作原型,只要您在使用它之前对其进行了定义。所以,如果你在文件底部写入'main',你可以省略原型。 *有些人不喜欢底部的“main”;有些人不喜欢它的顶部;大声笑* – pmg
@pmg我会争辩说,没有必要写更多的原型而不是绝对必要的(我的意思是说,现在常用的语言有多少是他们需要的)的实际好处应该胜过任何美学偏好的排序的功能。干,所有这一切。 –