C 传递结构作为参数

标签 c struct aggregate-functions

我正在编写一个程序,其中将结构作为参数传递,但出现错误

void main()
{
    struct strucintcal
    {     
        char name[20];
        int numb;
        float amt;
    } xyz;

    void intcal(struct strucintcal);

    printf("\n Enter Customer Name: ");
    gets(xyz.name);

    printf("\nEnter Customer Nuber: ");
    scanf("%d",&xyz.numb);

    printf("\nEnter principal aomunt: ");
    scanf("%f", &xyz.amt);

    intcal(xyz);

    getch();
}

链接器错误: undefined symbol _intcal

最佳答案

你需要定义void intcal(struct strucintcal);:

void intcal(struct strucintcal s)
{
    s.field...
}

此外,通常通过指针传递结构更好:

void intcal(struct strucintcal *s)
{
    s->field...
}

关于C 传递结构作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20274475/

相关文章:

arrays - 如何通过引用将结构数组作为接口(interface)传递

c - 结构体和指向指针的指针

c - 使用结构体添加两个二维数组时出现段错误 11

具有相同ID的多行之间的SQL差异

MYSQL - 多个计数语句

mysql - 如何在单个查询中编写具有不同条件的两个不同的求和查询?

c - C编程中gets vs scanf vs fgets的区别

c - 全局值(value)没有得到体现

c - 重新分配() : invalid next size glibc detected

c - 在 C 中,如何确保初始化字符串的长度小于指定的长度