社区
C语言
帖子详情
怎么定义结构体子函数
tangcx
2003-10-18 04:14:36
我已经定了结构体struct student
并在 main()中定义
main()
{struct student *p,*head;
head=input(p);}
我想用子函数调用*P
是不是这样定义
struct student *input(struct student *p1)
{ 内容}
...全文
354
7
打赏
收藏
怎么定义结构体子函数
我已经定了结构体struct student 并在 main()中定义 main() {struct student *p,*head; head=input(p);} 我想用子函数调用*P 是不是这样定义 struct student *input(struct student *p1) { 内容}
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
laomai
2003-10-18
打赏
举报
回复
struct student
{string name; /* defined data structure*/
int number;
int mark;
struct student *next;
}; //你这少了一个关键的分号,呵呵
仔细看看结构体的语法,呵呵
laomai
2003-10-18
打赏
举报
回复
你的结构体定义结束处应该有分号!
常见的毛病,呵呵
tangcx
2003-10-18
打赏
举报
回复
这种定义方 struct student *delet ( struct student *head)在C语言中肯定能通过
tangcx
2003-10-18
打赏
举报
回复
#include<string>
#include<iostream>
#define Null 0
using namespace std;
struct student
{string name; /* defined data structure*/
int number;
int mark;
struct student *next;
}
struct student *delet ( struct student *head) /*delete function*/
{ struct student *p,*p1=head,*p2;
p2=p1;
cout<<"input the student number what you want to delete";
cin>>p->number;
while((p1->number!=p->number)&&(p1->number!=Null))
{p2=p1;p1=p1->next;}
if(p1->number=p->number)
{if(p1==head) head=p1->next;
else p2->next=p1->next;
}
return(head);}
main()
{struct student *p,*p1,*head,*p2;
char ch;
for(int i=1;i<=3;i++) /*input the data*/
{ p=new struct student;
cin>>p->name>>p->number>>p->mark;
if(i==1) head=p;
else p1->next=p;
p1=p;
}
p1->next=Null;
p2=head;
cout<<"do you want to insert the data(y\n)"<<endl;
cin>>ch;
if((ch=='y')||(ch=='Y')) p2=delet(head); /* call the delete function*/
while(p2!=Null) /*output the data*/
{cout<<p2->name<<p2->number<<p2->mark<<endl;
p2=p2->next;}
}
编译时:
:\C++\program\program.cpp(11) : error C2236: unexpected 'struct' 'student'
F:\C++\program\program.cpp(52) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.
program.exe - 1 error(s), 1 warning(s)
我怀疑是定义函数 struct student *delete (student *head)时有错误,我的书上又没有这样的说明
气死我也
tangcx
2003-10-18
打赏
举报
回复
定义一个删除子函数
struct student *delet ( struct student *head) /*delete function*/
{ struct student *p,*p1=head,*p2;
p2=p1;
cout<<"input the student number what you want to delete";
cin>>p->number;
while(p1->number!=p->number)&&(p1->number!=Null)
{p2=p1;p1=p1->next;}
if(p1->number=p->number)
{if(p1==head) head=p1->next;
else p2-next=p1->next;
}
return(head);}
编译时出现:
F:\C++\program\program.cpp(11) : error C2236: unexpected 'struct' 'student'
F:\C++\program\program.cpp(11) : error C2059: syntax error : 'delete'
F:\C++\program\program.cpp(12) : error C2143: syntax error : missing ';' before '{'
F:\C++\program\program.cpp(12) : error C2447: missing function header (old-style formal list?)
F:\C++\program\program.cpp(32) : error C2143: syntax error : missing ';' before '||'
F:\C++\program\program.cpp(41) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.
program.obj - 5 error(s), 1 warning(s)
darcymei
2003-10-18
打赏
举报
回复
nod . no problem!
晨星
2003-10-18
打赏
举报
回复
函数要实现什么功能?什么又叫“结构体子函数”?
图书馆管理系统
在程序中主要
定义
了struct book,struct jieshu的图书信息
结构体
和借书人
结构体
,文件,查询chaxun()
函数
,添加tianjia()
函数
等等,另外还有相关调用
子
函数
,如排序
函数
,选择
函数
等。 系统包含以下基本功能:...
免费下载:C语言难点分析整理.doc
29. exit
子
程序终止
函数
与return的差别 141 30. extern与static存储空间矛盾 145 31. PC-Lint与C\C++代码质量 147 32. spirntf
函数
使用大全 158 33. 二叉树的数据结构 167 34. 位运算应用口诀和实例 170 35. 内存...
c语言中
结构体
在
子
函数
中的用法
在c语言中,
结构体
是一种很常用的数据结构,但是要用好却又有许多疑惑。 假设下面这个是我们要用到的
结构体
...首先来看一下这两个句
子
在
子
函数
中的区别。 data * dt1=(data*)malloc(sizeof(data)
结构体
的
函数
调用及嵌套
结构体
及
结构体
数组的
函数
调用问题,值传递还是地址传递。
结构体
之
结构体
作为
函数
参数
结构体
作为
函数
参数 作用:将
结构体
作为参数向
函数
中传递 一般来说
函数
的参数传递方式有两种: 值传递 地址传递 具体可以参照这边文章 https://blog.csdn.net/zhang2039/article/details/108547625一般来说
函数
的...
C语言
69,368
社区成员
243,082
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章