传递结构的功能 [英] Passing struct to function

查看:151
本文介绍了传递结构的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新的C程序员,我想知道我可以通过一个函数传递结构。我发现了一个错误,无法找出正确的语法来做到这一点。这里是code吧....

结构

 结构学生{
        焦姓[30];
        焦姓[30];
    };    结构的学生的人;

电话:

 传递addStudent(人);

原型:

 无效传递addStudent(结构的学生);

和实际的功能:

 无效传递addStudent(人)
{
    返回;
}

编译器错误:


  21行:警告:可疑标记声明:学生结构
行223:参数#1是不​​兼容的原型:



解决方案

线功能的实现应该是:

 无效传递addStudent(结构学生人){}

不是一个类型,但变量,你不能用它作为函数参数的类型。

另外,确保你的结构是函数的原型之前定义的传递addStudent 为原型使用它。

I'm a new C programmer and I wanted to know how I can pass a struct through to a function. I'm getting an error and can't figure out the correct syntax to do it. Here is the code for it....

struct:

struct student{
        char firstname[30];
        char surname[30];
    };

    struct student person;

call:

addStudent(person);

prototype:

void addStudent(struct student);

and the actual function:

void addStudent(person)
{
    return;
}

compiler errors:

line 21: warning: dubious tag declaration: struct student
line 223: argument #1 is incompatible with prototype:

解决方案

The line function implementation should be:

void addStudent(struct student person) {

}

person is not a type but a variable, you cannot use it as the type of a function parameter.

Also, make sure your struct is defined before the prototype of the function addStudent as the prototype uses it.

这篇关于传递结构的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆