Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 访问结构的副本。我得到一个错误:请求成员‘;计数’;在非结构或联盟中_C_Pointers_Struct - Fatal编程技术网

C 访问结构的副本。我得到一个错误:请求成员‘;计数’;在非结构或联盟中

C 访问结构的副本。我得到一个错误:请求成员‘;计数’;在非结构或联盟中,c,pointers,struct,C,Pointers,Struct,由于某些原因,我无法访问procNames.count。我所需要做的就是增加计数器。我不知道为什么。有人看到问题了吗 struct config_line { char name[MAX_WORD]; int time; }; struct config { struct config_line *lines; int count; }; //global variable struct config configData; // allocate memo

由于某些原因,我无法访问procNames.count。我所需要做的就是增加计数器。我不知道为什么。有人看到问题了吗

struct config_line {
    char name[MAX_WORD];
    int time;
};

struct config {
    struct config_line *lines;
    int count;
};

//global variable
struct config configData;

// allocate memory to procNames
procNames = malloc(sizeof(struct config));
if ( procNames == NULL ) {
    printf("problem allocating memory, for procNames. int procnanny(void)");
    return 0;       
}
//local variable
struct config *procNames;

procNames = &configData;
// the problem
procNames.count++;
使用:

procNames
是指针,因此您需要使用该指针或冗长的:

(*procNames).count++;
仅当LHS上的值为结构时,才能使用
运算符。当有指向结构的指针时,必须使用
->
或取消引用指针,然后应用
运算符,该运算符需要括号和
*
,因为
绑定比一元数(取消引用)
*

使用:

procNames
是指针,因此您需要使用该指针或冗长的:

(*procNames).count++;
仅当LHS上的值为结构时,才能使用
运算符。当有指向结构的指针时,必须使用
->
或取消引用指针,然后应用
运算符,该运算符需要括号和
*
,因为
绑定比一元数(取消引用)
*

更紧

procNames->count++
应该是吗

procNames->count++