#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
//顺序表的训练 以学生记录为基础
#define MAXNAME 30
#define MAXPERSON 20
#define bool int
#define false 0
#define true 1
struct student
{
char s_name[MAXNAME];
int s_num;
char s_sex;
char s_class[MAXNAME];
};
struct node
{
struct student std[MAXPERSON];
int length ;
int listsize ;
};
void InitList(struct node **list)//建立顺序表
{
*list = (struct node*)malloc(sizeof(struct node));
if (!*list)
return ;
else
{
(*list)->length = 0;
(*list)->listsize = MAXPERSON;
}
}
void ClearList(struct node *list)//清空顺序表
{
if (list)
{
free(list);
return;
}
printf("the list is empty \n");
return;
}
bool ListEmpty(struct node *list)//返回是否为空
{
if (list)
return false;
else
return true;
}
int ListLength(struct node *list)//返回线性表的长度
{
if (list)
return list->length;
else
return 0;
}
bool GetElem(struct node *list, int i, struct student *e)//用e保存返回的元素
{
if (list)
{
if (i <= list->length && i >= 1)
{
*e = list->std[i - 1];//返回第i个数据元素
return true;
}
}
return false;
}
int main(void)
{
struct node *List=NULL;
InitList(&List);
ClearList(List);
int j = 0,i=0;//下标
for (;i <3;i++)
{
struct student temp;
printf("please input student's name num sex class \n");
if (fscanf(stdin,"%s %d %c %s", temp.s_name, &temp.s_num, &temp.s_sex, temp.s_class)== 4)
{
List->std[j];//此处有错
(List->length)++;
j++;
}
printf("input error\n");
}
struct student temp;
if (GetElem(List,1,&temp))
printf("%s %d %c %s\n", temp.s_name, temp.s_num, temp.s_sex, temp.s_class);
else
printf("not exist the element\n");
}
List->std[j];//此处有错
这个语句是什么鬼,。。。。。。有作用吗?