传递结构指针 [英] Passing structure as pointer
本文介绍了传递结构指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过结构的函数参数指针。这里是我的code
I'm trying to pass structure as pointer in function arguments. Here is my code
#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);
}
我得到一个错误路过的汽车不兼容型轿车的参数。我错过了什么?
I get an error "Passing Car to parameter of incompatible type Car. What I miss ?
推荐答案
转发的声明应该是:
void PrintCarDetails(Car * details);
这篇关于传递结构指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文