error: initializer element is not constant 错误

djinglan 2012-04-09 04:23:59
typedef struct student {
char name[20]
char phone[20];
bool flag;
struct student *next;
}stu;

stu *Read(stu * phead);
struct student *head = NULL;

head = Read(head);


phonetext.c:22: warning: data definition has no type or storage class
phonetext.c:22: error: conflicting types for ‘head’
phonetext.c:20: note: previous definition of ‘head’ was here
phonetext.c:22: warning: passing argument 1 of ‘Read’ makes pointer from integer without a cast
phonetext.c:14: note: expected ‘struct stu *’ but argument is of type ‘int’
phonetext.c:22: warning: initialization makes integer from pointer without a cast
phonetext.c:22: error: initializer element is not constant
phonetext.c: In function ‘Schedle’:


不知道怎么解决,谢谢帮忙。
...全文
1072 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
djinglan 2012-04-09
  • 打赏
  • 举报
回复
问题解决了。
原因在于 struct student *head = NULL;
head = Read(head);

在main()函数外,这种写法在gcc 编译其中不能使用,但是在g++ 编译其中支持这种写法。

改正该错误的方法是 在mian中 调用 head = Read(head);即可成功。


非常感谢大家的帮助,非常感谢。
Wenxy1 2012-04-09
  • 打赏
  • 举报
回复
用c99标准,试试加-std=c99
djinglan 2012-04-09
  • 打赏
  • 举报
回复
非常抱歉,粘贴的不好。
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

typedef struct student
{
char name[20];
char phone[20];
bool flag;
struct student *next;
}stu;

struct student * Read(struct student *phead);
stu *Add(stu *phead);
void Write(stu *phead);
void Search(stu *phead);
void Delete(stu *phead);
void Modify(stu *phead);
struct student *head = Read(head);

void Schedle()
{
while(true)
{
printf("\n输入操作命令:>");
char command[20];
scanf("%d",&command);
if (strcmp(command,"add") == 0)
{
head = Add(head);
}
else if (strcmp(command,"update") == 0)
{
Modify(head);
}
else if (strcmp(command,"delete") == 0)
{
Delete(head);
}
else if (strcmp(command,"find") == 0)
{
Search(head);
}
else if(strcmp(command,"exit") == 0)
{
Write(head);
exit(0);
}
else
{
printf("对不起,您输入了不能识别的命令\n");
}
}
djinglan 2012-04-09
  • 打赏
  • 举报
回复
else
51 {
52 printf("对不起,您输入了不能识别的命令\n");
53 }
54 }
djinglan 2012-04-09
  • 打赏
  • 举报
回复
124 {
125 printf("姓名:%s |电话号码:%s 记录将要清除,请确认(yes/no):", ps->nam
126 char command[20];
127 scanf("%s",command);
128 if (strcmp(command, "yes") == 0)
129 {
130 ps->flag = true;
131 printf("记录清除完毕\n");
132 }
133 else
134 {
135 printf("查无记录\n");
136 }
137 }
138 }
139
140
141 void Modify(stu *phead)
142 {
143 stu *ps = Find(phead);
144 if (ps != NULL)
145 {
146 printf("姓名:%s |电话号码: %s\n",ps->name,ps->phone);
147 char name[20];
148 char phone[20];
149 printf("请输入要修改后的名字:");
150 scanf("%s",name);
151 printf("请输入要修改后的电话号码:");
152 scanf("%s",phone);
153 strcpy(ps->phone,phone);
154 strcpy(ps->name,name);
155 printf("记录修改望比\n");
156 }
157 else
158 {
159 printf("查无记录\n");
160 }
161 }
162
163 stu * Read(stu *phead)
164 {
165 FILE *fp = fopen("data.dat", "rb");
166 if (fp == NULL)
158,5 48%
wwyyxx26 2012-04-09
  • 打赏
  • 举报
回复
你这代码也没有几行,要不都打出来看看?
昵称很不好取 2012-04-09
  • 打赏
  • 举报
回复
head重定义了,看看phonetext.c的第20行,是不是也定义了head
djinglan 2012-04-09
  • 打赏
  • 举报
回复
已经定义了head ,如下

stu *Read(stu * phead);
struct student *head = NULL;

head = Read(head);

实在是找不到有什么问题,还有就是,c99标准,只支持全局变量和static变量,定义时初始化,但是,我试了另外的定义方式,struct student *head = Read(head);
这样也是出现上述问题,请指点。谢谢
Wenxy1 2012-04-09
  • 打赏
  • 举报
回复
phonetext.c:22: error: conflicting types for ‘head’

检查phonetext.c文件的22行, 冲突的head类型. 是否包含了相应的头文件,或者是否定义了head 类型。
笔记本的风扇控制 ---------------------------------------- 09 November 2006. Summary of changes for version 20061109: 1) ACPI CA Core Subsystem: Optimized the Load ASL operator in the case where the source operand is an operation region. Simply map the operation region memory, instead of performing a bytewise read. (Region must be of type SystemMemory, see below.) Fixed the Load ASL operator for the case where the source operand is a region field. A buffer object is also allowed as the source operand. BZ 480 Fixed a problem where the Load ASL operator allowed the source operand to be an operation region of any type. It is now restricted to regions of type SystemMemory, as per the ACPI specification. BZ 481 Additional cleanup and optimizations for the new Table Manager code. AcpiEnable will now fail if all of the required ACPI tables are not loaded (FADT, FACS, DSDT). BZ 477 Added #pragma pack(8/4) to acobject.h to ensure that the structures in this header are always compiled as aligned. The ACPI_OPERAND_OBJECT has been manually optimized to be aligned and will not work if it is byte-packed. Example Code and Data Size: These are the sizes for the OS- independent acpica.lib produced by the Microsoft Visual C++ 6.0 32- bit compiler. The debug version of the code includes the debug output trace mechanism and has a much larger code and data size. Previous Release: Non-Debug Version: 78.1K Code, 17.1K Data, 95.2K Total Debug Version: 155.4K Code, 63.1K Data, 218.5K Total Current Release: Non-Debug Version: 77.9K Code, 17.0K Data, 94.9K Total Debug Version: 155.2K Code, 63.1K Data, 218.3K Total 2) iASL Compiler/Disassembler and Tools: Fixed a problem where the presence of the _OSI predefined control method within complex expressions could cause an internal compiler error. AcpiExec: Implemented full region support for multiple address spaces. SpaceId is now part of the REGION object. BZ 429 ---------------------------------------- 11 Oc

23,128

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧