|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
typedef struct
{
char ID[8];
char name[9];
int score;
}student;
typedef struct
{
student *s;
int currentLength;
int length;
}seTable,*SeTable;
void initTable(seTable &L)
{
L.s = (student*)malloc(sizeof(student) * MAXSIZE);
L.currentLength = 0;
L.length = MAXSIZE;
}
void inputTable(seTable &L)
{
int n;
printf("请输入要入表的学生人数:\n");
scanf_s("%d", &n);
for (int i = 0; i < n; i++)
{
printf("请输入第%d位学生姓名\n",i+1);
scanf_s("%s",& L.s->name,sizeof(L.s->name));
printf("请输入第%d位学生学号\n", i + 1);
scanf_s("%s", &L.s->ID,sizeof(L.s->ID));
printf("请输入第%d位学生成绩\n", i + 1);
scanf_s("%d", &L.s->score);
L.currentLength++;
}
printf("录入成功!\n");
}
void printTable(seTable& L) //输出顺序表元素 这个函数应该怎么写?
{
student* z = L.s;
for (z;L.s<L.s+L.currentLength;z++)
{
printf("姓名:%s,学号:%s,分数:%d",z->name,z->ID,z->score);
}
}
int main()
{
seTable L;
initTable(L);
inputTable(L);
printTable(L);
return 0;
} |
|