相关疑难解决方法(0)

修改作为指针传递的结构 - C

我试图通过使用指针来修改作为参数传递的结构,但是我无法使其工作.我不能只返回结构,因为该函数必须返回一个整数.如何修改函数中的结构?这是我到目前为止所做的:

typedef enum {TYPE1, TYPE2, TYPE3} types;

typedef struct {
                types type;
                int act_quantity;
                int reorder_threshold;
                char note[100];

}elem;

int update_article(elem *article, int sold)
{
    if(*article.act_quantity >= sold)
    {
        article.act_quantity = article.act_quantity - sold;
        if(article.act_quantity < article.act_quantity)
        {
            strcpy(article.note, "to reorder");
            return -1;
        }
        else
            return 0;
    }
    else if(article.act_quantity < venduto)
    {
        strcpy(*article.note, "act_quantity insufficient");
        return -2;
    }


}
Run Code Online (Sandbox Code Playgroud)

我得到这个错误:"错误:请求成员:'act_quantity'在某些东西中不是结构或联合'"在我尝试修改结构的所有行中.

编辑:我用过"." 而不是" - >".我现在修好了.它仍然给我一个错误:"一元'*'的无效类型参数(有'int')"

c struct function

2
推荐指数
2
解决办法
3109
查看次数

标签 统计

c ×1

function ×1

struct ×1