Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.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错误:C2040:&x27;customerPtr';:';int';与';客户*';_C_Struct_Initialization_Variable Assignment - Fatal编程技术网

C错误:C2040:&x27;customerPtr';:';int';与';客户*';

C错误:C2040:&x27;customerPtr';:';int';与';客户*';,c,struct,initialization,variable-assignment,C,Struct,Initialization,Variable Assignment,对于C来说,这是一个非常新的问题。当我运行我的指导老师给我们的代码时,我总是遇到这个错误 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <time.h> #include <stdlib.h> //Create a struct for customers struct customer { cha

对于C来说,这是一个非常新的问题。当我运行我的指导老师给我们的代码时,我总是遇到这个错误

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>

//Create a struct for customers
struct customer
{
char lastName[15];
char firstName[15];
unsigned int customerNumber;
};


struct customer customerRecord;
struct customer *customerPtr;
struct customer other;

customerPtr = &customerRecord;

//typedef struct customer to customer
typedef struct customer customer;

char main()
{
//customerRecord.lastName = Flacco;

}
#包括
#包括
#包括
#包括
#包括
#包括
//为客户创建结构
结构客户
{
char lastName[15];
charfirstname[15];
无符号整数客户编号;
};
结构客户记录;
结构客户*customerPtr;
结构客户其他;
customerPtr=&customerRecord;
//typedef结构客户对客户
类型定义结构客户;
char main()
{
//customerRecord.lastName=Flacco;
}
我得到了错误 错误C2040:'customerPtr':'int'与'customer*'的间接寻址级别不同

我读过其他类似的帖子,但我想我不明白
与他们的计划有关

谢谢

此分配错误(不允许在全局范围内进行分配):

您应使用以下选项进行更改:

...
struct customer customerRecord;
struct customer *customerPtr = &customerRecord;  /* definition & initialization */
struct customer other;
...

另外,
main
的返回类型应为
int

此赋值错误(不允许在全局范围内赋值):

您应使用以下选项进行更改:

...
struct customer customerRecord;
struct customer *customerPtr = &customerRecord;  /* definition & initialization */
struct customer other;
...


另外,
main
的返回类型应该是
int

哪一行代码会给你错误消息?在我多年的编码工作中,使用像这样的论坛和c.l.c,我从未见过
char main()
。谢谢你的笑声:)请注意,包含
与只包含一次相比,不会给你带来任何好处是问题所在;不能在全局范围内编写作业。不过,您可能有理由想知道
int
从何而来。我认为编译器必须假设(第二次声明的)
customerPtr
的类型是
int
,因为您没有指定类型,并且该类型不是赋值的正确类型,因此出现警告。我很惊讶你在重新定义
customerPtr
时没有遇到错误,但是编译器可以自由地诊断任何东西,只要它对错误程序至少给出一个诊断。哪一行代码会给你错误信息?在我多年的编码过程中,使用像这样的论坛和c.l.c,我从未见过
charmain()
。谢谢你的笑声:)请注意,包含
与只包含一次相比,不会给你带来任何好处是问题所在;不能在全局范围内编写作业。不过,您可能有理由想知道
int
从何而来。我认为编译器必须假设(第二次声明的)
customerPtr
的类型是
int
,因为您没有指定类型,并且该类型不是赋值的正确类型,因此出现警告。我很惊讶您在重新定义
customerPtr
时没有遇到错误,但是编译器可以随意诊断任何东西,只要它对错误的程序至少给出一个诊断。
struct customer customerRecord;
struct customer *customerPtr;  /* definition */
struct customer other;

...

int main()
{
  customerPtr = &customerRecord;  /* initialization */

  ...
}