在链表创建和输出中遇到的问题

#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'相关推荐

  1. c语言中错误c2228,错误:C2228:''必须有class/struct/union

    我是一个很长时间的Java用户用Qt学习C++,我在理解方法如何工作方面遇到了很多麻烦.现在,我正在试图找出数据库,并试图用标题简化我的代码.通常在Java中我只有一个名为DatabaseContro ...

  2. [SV]SystemVerilog学习笔记之struct union

    SystemVerilog学习笔记(四) 一.结构体(struct) 1.1.结构体声明(struct) 结构体声明:结构体默认是变量,也可以声明为线网 var struct { // 通过var进行 ...

  3. 对error C2079: 'stu' uses undefined struct 'Students'的解释

    以下是错误程序源代码举例(其实是我自己在学习过程中出现的错误): #include <stdio.h> struct Date {int year;int month; }; struct ...

  4. 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 ...

  5. Java. Warning – Build path specifies execution environment J2SE-1.5

    MyEclipse新建Web Project 之后显示警告信息,我们想除之而后快. 查看全文 http://www.taodudu.cc/news/show-5159156.html 相关文章: Xa ...

  6. 如何在JAVA程序中使用Struct一次传入多条数据给Oracle的存储过程

    http://blog.csdn.net/dutguoyi/article/details/1879416 为了减少连接Oracle数据库的数量,需要将多条数据作为变量一次传入Oracle的存储过程中 ...

  7. racle的STRUCT和VARRAY的读写方法

    Oracle的STRUCT和VARRAY的读写方法 巧巧电脑网络 2010-02-25 qqread 佚名   收藏此文  大 中小 分享到 QQ空间 人人网 开心网 豆瓣 新浪微博腾讯微博更多 本文 ...

  8. go struct{} 空结构体的特点和作用

    空结构体的特点和作用 参考代码 package mainimport ("fmt""unsafe" )func main() {empStruct() } // ...

  9. struct和typedef struct彻底明白了,引用自https://www.cnblogs.com/qyaizs/articles/2039101.html

    struct和typedef struct彻底明白了 struct和typedef struct 分三块来讲述: 1 首先://注意在C和C++里不同 在C中定义一个结构体类型要用typedef: t ...

最新文章

  1. android webview tel:,Android WebView“tel:”链接显示未找到网页
  2. informix如何查询第一条记录
  3. 在Qt Creator中添加OpenCV库
  4. shell字符串是否以a-zA-Z字母开头
  5. 拿着 22 万美元年薪,混得还不如实习生?
  6. Atitit 价值观与理念总结 Diy自力更生尽可能 提高独立性 减少依赖 大而全优先于小而美 适度分权防止集权导致大决策失误 方式多种多样 综合是王道 简单快速优先 努力实现人们喜闻乐见的服务 信
  7. DBC 2000 安装
  8. 前台CSS颜色代码大全
  9. 优派 ELITE XG320Q、XG320U / UG 评测
  10. 遥感影像人口数据、气象数据、社会统计数据、GDP空间分布数据
  11. Ubuntu v18.04安装网易云音乐
  12. 剪映专业版 - 你的短视频剪辑小帮手!附Mac/Win地址!
  13. 环保性能高的家装乳胶漆怎么选择
  14. suse linux乱码,轻松解决Suse中文乱码问题
  15. 抖音一键生成的AI绘画火了,网友惊呼:有点东西
  16. 腾讯、阿里、京东员工下班不回家,原因竟然是……
  17. 国内SSD品牌如何异军突起
  18. 计算机更换硬盘键盘鼠标不好使,计算机上安装的原始Win7系统的鼠标和键盘无法移动硬盘,并且无法识别解决方案...
  19. Gym102870 2020-2021 “Orz Panda” Cup Programming Contest 补题记录
  20. 超螺旋滑模控制(STA)

热门文章

  1. 微信小助手WeChatExtension中文版v1.7.8支持最新版
  2. 恢复Word默认设置,将Word还原到初始状态
  3. 中国人为什么不愿意消费
  4. 使用GitHub管理Repository
  5. Ambiguous column reference id in t
  6. Vage:高级DBA的突破之路
  7. Ubuntu删除ppa
  8. 计算机专业校运会加油稿,软件学院运动会加油稿
  9. centos根分区扩容方法linux公社,CentOS根分区扩容方法
  10. VR虚拟现实游戏长沙VR体验馆哪家好