| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 401 人关注过本帖
标题:[求助]链表问题
取消只看楼主 加入收藏
sunpy
Rank: 1
来 自:厦门
等 级:新手上路
帖 子:118
专家分:0
注 册:2007-10-1
结帖率:100%
收藏
 问题点数:0 回复次数:2 
[求助]链表问题
大虾帮帮小弟,小弟谢万分啊!

#include"stdlib.h"
#include"stdio.h"

struct stud
{
char name[20];
long num;
int age;
char sex;
float score;
struct stud *next;
};
struct stud *head, *this, *new;
void listall(void);
void new_record(void);
int
main()
{
char ch;
int flag=1;
head=NULL;
printf("***************************************************************\n");
printf("| welcome to use ! |\n");
printf("| |\n");
printf("| All rights resevered 03101 Huang wenmin |\n");
printf("*********~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**********\n");
while(flag)
{
printf("\ntype'E'or'e'to enter new record,");
printf("\ntype'L'or'l'to list all records:");
ch=getchar();getchar();
switch(ch)
{
case'e':
case'E':new_record();break;
case'l':
case'L':listall();break;
default:flag=0;
}
}
}
new_record(void)
{
char numstr[20];
new=(struct stud *) malloc (sizeof (struct stud));
if(head==NULL)
head=new;
else
{
this=head;
while (this->next!=NULL)
this=this->next;
this->next=new;
}
this=new;
printf("\nenter name:");
gets(this->name);
printf("\nenter number:");
gets(numstr);
this->num=atol(numstr);
printf("\nenter age:");
gets(numstr);
this->age=atoi(numstr);
printf("\nenter sex:");
this->sex=getchar();getchar();
printf("\nenter score:");
gets (numstr);
this->score=atof(numstr);
this->next=NULL;
}
listall(void)
{
int i=0;
if(head==NULL)
{
printf("\nempty list. \n");return;}
this=head;
do
{
printf("\nrecord number %d\n",++i);
printf("name:%s\n",this->name);
printf("num:%ld\n",this->num);
printf("age:%d\n",this->age);
printf("sex:%c\n",this->sex);
printf("score:%6.2f\n",this->score);
this=this->next;
}
while(this!=NULL);
}
}
编译后的结果是--------------------Configuration: 21-2 - Debug--------------------
Compiling source file(s)...
1.cpp
1.cpp:13: error: expected unqualified-id before "this"
1.cpp:13: error: expected init-declarator before "this"
1.cpp:13: error: expected `,' or `;' before "this"
1.cpp:43: error: ISO C++ forbids declaration of `new_record' with no type
1.cpp: In function `int new_record()':
1.cpp:43: error: new declaration `int new_record()'
1.cpp:15: error: ambiguates old declaration `void new_record()'
1.cpp: In function `int new_record()':
1.cpp:45: error: expected identifier before '=' token
1.cpp:47: error: expected identifier before ';' token
1.cpp:50: error: invalid use of `this' in non-member function
1.cpp:51: error: invalid use of `this' in non-member function
1.cpp:52: error: invalid use of `this' in non-member function
1.cpp:52: error: invalid use of `this' in non-member function
1.cpp:53: error: invalid use of `this' in non-member function
1.cpp:53: error: expected identifier before ';' token
1.cpp:55: error: invalid use of `this' in non-member function
1.cpp:55: error: expected identifier before ';' token
1.cpp:57: error: invalid use of `this' in non-member function
1.cpp:60: error: invalid use of `this' in non-member function
1.cpp:63: error: invalid use of `this' in non-member function
1.cpp:65: error: invalid use of `this' in non-member function
1.cpp:68: error: invalid use of `this' in non-member function
1.cpp:69: error: invalid use of `this' in non-member function
1.cpp: At global scope:
1.cpp:72: error: ISO C++ forbids declaration of `listall' with no type
1.cpp: In function `int listall()':
1.cpp:72: error: new declaration `int listall()'
1.cpp:14: error: ambiguates old declaration `void listall()'
1.cpp: In function `int listall()':
1.cpp:76: error: return-statement with no value, in function returning 'int'
1.cpp:77: error: invalid use of `this' in non-member function
1.cpp:81: error: invalid use of `this' in non-member function
1.cpp:82: error: invalid use of `this' in non-member function
1.cpp:83: error: invalid use of `this' in non-member function
1.cpp:84: error: invalid use of `this' in non-member function
1.cpp:85: error: invalid use of `this' in non-member function
1.cpp:86: error: invalid use of `this' in non-member function
1.cpp:86: error: invalid use of `this' in non-member function
1.cpp:88: error: invalid use of `this' in non-member function
1.cpp: At global scope:
1.cpp:90: error: expected declaration before '}' token

21-2.exe - 36 error(s), 0 warning(s)
那个“this”怎么用错了?


搜索更多相关主题的帖子: 链表 
2007-10-21 12:07
sunpy
Rank: 1
来 自:厦门
等 级:新手上路
帖 子:118
专家分:0
注 册:2007-10-1
收藏
得分:0 
回复:(sunpy)[求助]链表问题
论坛上的一个老题目。。。。。。。。。。

荀子《劝学》:“不积跬步,无以至千里;不积小流,无以成江海.”
2007-10-21 12:09
sunpy
Rank: 1
来 自:厦门
等 级:新手上路
帖 子:118
专家分:0
注 册:2007-10-1
收藏
得分:0 
自己再顶一次。。。。


荀子《劝学》:“不积跬步,无以至千里;不积小流,无以成江海.”
2007-10-21 12:25
快速回复:[求助]链表问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029538 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved