left of 'name' specifies undefined struct/union '$S1'
在链表创建和输出中遇到的问题
#include <stdio.h>
#include <stdlib.h>
struct student
{
char name[20];
int num;
struct student *next;
};
int cnt;
struct student *create()
{
struct student *phead=NULL;
struct *pend,*pnew;
cnt=0;
pend=pnew=(struct student *)malloc(sizeof(struct student));
printf("please first enter name num:\n");
scanf("%s",pnew->name);
scanf("%d",&pnew->num);
while(pnew->num!=0)
{
cnt++;
if(cnt==1)
{
pnew->next=phead;
pend=pnew;
phead=pnew;
}
else
{
pnew->next=NULL;
pend->next=pnew;
pend=pnew;
}
pnew=(struct student*)malloc(sizeof(struct student));
scanf("%s",pnew->name);
scanf("%d",&pnew->num);
}
free(pnew);
return (phead);
}
void print(struct student *phead)
{
struct student *ptemp;
int n=1;
printf("********本名单中有%d个学生:********\n",cnt);
ptemp=phead;
while(ptemp!=NULL)
{
printf("第%d个学生是:\n",n);
printf("姓名:%s\n",ptemp->name);
printf("学号:%d\n",ptemp->num);
ptemp=ptemp->next;
n++;
}
}
int main(void)
{
struct student *phead;
phead=create();
print(phead);
return 0;
}
错误信息:
isual Studio\MyProjects\11\11.c(15) : warning C4133: '=' : incompatible types - from 'struct student *' to 'struct $S1 *'
D:\Program Files\Microsoft Visual Studio\MyProjects\11\11.c(17) : error C2037: left of 'name' specifies undefined struct/union '$S1'
D:\Program Files\Microsoft Visual Studio\MyProjects\11\11.c(18) : error C2037: left of 'num' specifies undefined struct/union '$S1'
D:\Program Files\Microsoft Visual Studio\MyProjects\11\11.c(19) : error C2037: left of 'num' specifies undefined struct/union '$S1'
D:\Program Files\Microsoft Visual Studio\MyProjects\11\11.c(24) : error C2037: left of 'next' specifies undefined struct/union '$S1'
D:\Program Files\Microsoft Visual Studio\MyProjects\11\11.c(26) : warning C4133: '=' : incompatible types - from 'struct $S1 *' to 'struct student *'
D:\Program Files\Microsoft Visual Studio\MyProjects\11\11.c(30) : error C2037: left of 'next' specifies undefined struct/union '$S1'
D:\Program Files\Microsoft Visual Studio\MyProjects\11\11.c(31) : error C2037: left of 'next' specifies undefined struct/union '$S1'
D:\Program Files\Microsoft Visual Studio\MyProjects\11\11.c(35) : warning C4133: '=' : incompatible types - from 'struct student *' to 'struct $S1 *'
D:\Program Files\Microsoft Visual Studio\MyProjects\11\11.c(36) : error C2037: left of 'name' specifies undefined struct/union '$S1'
D:\Program Files\Microsoft Visual Studio\MyProjects\11\11.c(37) : error C2037: left of 'num' specifies undefined struct/union '$S1'
总结问题:
错误信息提示 左边的 name 和 num 不是一个结构体 是因为在创建 create 的时候 有一个 struct *pnew,*pend出了问题 因为在定义结构体指针变量的时候 这种格式是错误的 应该是 struct 结构体名 *指针变量名 ,我刚才漏掉了结构体变量名 所以出现了问题。
left of 'name' specifies undefined struct/union '$S1'相关推荐
- c语言中错误c2228,错误:C2228:''必须有class/struct/union
我是一个很长时间的Java用户用Qt学习C++,我在理解方法如何工作方面遇到了很多麻烦.现在,我正在试图找出数据库,并试图用标题简化我的代码.通常在Java中我只有一个名为DatabaseContro ...
- [SV]SystemVerilog学习笔记之struct union
SystemVerilog学习笔记(四) 一.结构体(struct) 1.1.结构体声明(struct) 结构体声明:结构体默认是变量,也可以声明为线网 var struct { // 通过var进行 ...
- 对error C2079: 'stu' uses undefined struct 'Students'的解释
以下是错误程序源代码举例(其实是我自己在学习过程中出现的错误): #include <stdio.h> struct Date {int year;int month; }; struct ...
- C++:error C2228: left of '.str' must have class/struct/union
如下代码报error C2228: left of '.str' must have class/struct/union #include <string> #include <i ...
- Java. Warning – Build path specifies execution environment J2SE-1.5
MyEclipse新建Web Project 之后显示警告信息,我们想除之而后快. 查看全文 http://www.taodudu.cc/news/show-5159156.html 相关文章: Xa ...
- 如何在JAVA程序中使用Struct一次传入多条数据给Oracle的存储过程
http://blog.csdn.net/dutguoyi/article/details/1879416 为了减少连接Oracle数据库的数量,需要将多条数据作为变量一次传入Oracle的存储过程中 ...
- racle的STRUCT和VARRAY的读写方法
Oracle的STRUCT和VARRAY的读写方法 巧巧电脑网络 2010-02-25 qqread 佚名 收藏此文 大 中小 分享到 QQ空间 人人网 开心网 豆瓣 新浪微博腾讯微博更多 本文 ...
- go struct{} 空结构体的特点和作用
空结构体的特点和作用 参考代码 package mainimport ("fmt""unsafe" )func main() {empStruct() } // ...
- struct和typedef struct彻底明白了,引用自https://www.cnblogs.com/qyaizs/articles/2039101.html
struct和typedef struct彻底明白了 struct和typedef struct 分三块来讲述: 1 首先://注意在C和C++里不同 在C中定义一个结构体类型要用typedef: t ...
最新文章
- android webview tel:,Android WebView“tel:”链接显示未找到网页
- informix如何查询第一条记录
- 在Qt Creator中添加OpenCV库
- shell字符串是否以a-zA-Z字母开头
- 拿着 22 万美元年薪,混得还不如实习生?
- Atitit 价值观与理念总结 Diy自力更生尽可能 提高独立性 减少依赖 大而全优先于小而美 适度分权防止集权导致大决策失误 方式多种多样 综合是王道 简单快速优先 努力实现人们喜闻乐见的服务 信
- DBC 2000 安装
- 前台CSS颜色代码大全
- 优派 ELITE XG320Q、XG320U / UG 评测
- 遥感影像人口数据、气象数据、社会统计数据、GDP空间分布数据
- Ubuntu v18.04安装网易云音乐
- 剪映专业版 - 你的短视频剪辑小帮手!附Mac/Win地址!
- 环保性能高的家装乳胶漆怎么选择
- suse linux乱码,轻松解决Suse中文乱码问题
- 抖音一键生成的AI绘画火了,网友惊呼:有点东西
- 腾讯、阿里、京东员工下班不回家,原因竟然是……
- 国内SSD品牌如何异军突起
- 计算机更换硬盘键盘鼠标不好使,计算机上安装的原始Win7系统的鼠标和键盘无法移动硬盘,并且无法识别解决方案...
- Gym102870 2020-2021 “Orz Panda” Cup Programming Contest 补题记录
- 超螺旋滑模控制(STA)