[求助]链表问题
大虾帮帮小弟,小弟谢万分啊!#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”怎么用错了?