为什么编译不通过??
我快想到暴胎了~~~#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
int num,p_num;
char *name;
struct student *next;
};
typedef struct student s_data;
s_data *top=NULL;
void chunru(int,char *,int);
void chaxun(char *);
void print_s(s_data *);
void print_student();
void freeme();
int main()
{
int select,num,p_num;
char name[10];
do
{
printf("(1)存入 (2)查询 (3)遍历 (4)离开");
scanf("%d",&select);
switch (select)
{
case 1:
printf("学号 姓名 电话号码:");
scanf("%d %s %11d",&num,name,&p_num);
chunru(num,name,p_num);
break;
case 2:
printf("请输入要查询的姓名:");
scanf("%s",name);
chaxun(name);
break;
case 3:
printf_student();
break;
}
}while (select != 4);
freeme();
system("pause");
return 0;
}
void chunru(int num,char* name,int p_num)
{
s_data *new_data;
new_data=(s_data *)malloc(sizeof(s_data));
strcpy(new_data->name,name);
new_data->num=num;
new_data->p_num=p_num;
new_data->next=top;
top=new_data;
}
void chaxun(char *name)
{
int same=0;
if (top=NULL)
printf("无此数据!\n");
else
{
s_data *ptr=top;
do
{
if ((strcmp(name,ptr->name)==0)
{
print_s(ptr);
puts("----------------------------------------");
same=1;
}
else
ptr=ptr->next;
}while ((ptr==NULL)||(same=1));
}
if(same==0)
printf("无此数据!\n");
}
void print_s(s_data *pptr)
{
puts("----------------------------------------");
printf("学号\t姓名\t电话号码\n");
printf("%d\t%s\t%d\n",pptr->num,pptr->name,pptr->p_num);
}
void print_student()
{
if (top == NULL)
printf("无数据\n");
else
{
s_data *ptr;
ptr=top;
while (ptr != NULL)
{
print_s(&ptr);
ptr=ptr->next;
}
puts("----------------------------------------");
}
}
void freeme()
{
do
{
s_data *ptr;
ptr=top;
top=top->next;
free(ptr);
}while (top != NULL);
}
为什么编译时会出错?
用的是Dev-C++4.9.9.2
[[it] 本帖最后由 r251314w 于 2008-4-6 17:37 编辑 [/it]]