c语言编程 有关线性表 错误在哪?编译没错 执行时输入数据 -1 就是想输出时 摁回车就没反应了
#include"stdafx.h"#include"stdlib.h"typedefstructstudent{intnum;charname[20];intscore...
#include "stdafx.h"
#include "stdlib.h"
typedef struct student {
int num;
char name[20];
int score ;
}stu;
//
typedef struct list {
stu * student;
int length ;
int listsize ;
}SqList;
//构造空表 即初始化
void initList(SqList& L)
{
L.student=(stu*)malloc(100*sizeof(stu));
//if(!L.student)
//
L.length=0;
L.listsize=100;
}
//insert
void input(SqList &L)
{
int i=0 ;
do
{
printf("Input Num \n");
scanf("%d",&i);
if (i>=0)
{
L.student[i-1].num=i;
printf("Input data : Name Score And input -1 to end\n");
scanf("%s%d",&L.student[i-1].name,&L.student[i-1].score);
L.length++ ;
}
}
while(i!=-1);
}
//output
void output(SqList L)
{
int i=1 ;
while (i<=L.length);
{
printf("%-5d %13s %10d \n",L.student[i-1].num, L.student[i-1].name, L.student[i-1].score);
i++;
}
}
//main
int main(int argc, char* argv[])
{
SqList L ;
initList(L);
input(L);
output(L);
return 0;
}
//main 展开
#include "stdlib.h"
typedef struct student {
int num;
char name[20];
int score ;
}stu;
//
typedef struct list {
stu * student;
int length ;
int listsize ;
}SqList;
//构造空表 即初始化
void initList(SqList& L)
{
L.student=(stu*)malloc(100*sizeof(stu));
//if(!L.student)
//
L.length=0;
L.listsize=100;
}
//insert
void input(SqList &L)
{
int i=0 ;
do
{
printf("Input Num \n");
scanf("%d",&i);
if (i>=0)
{
L.student[i-1].num=i;
printf("Input data : Name Score And input -1 to end\n");
scanf("%s%d",&L.student[i-1].name,&L.student[i-1].score);
L.length++ ;
}
}
while(i!=-1);
}
//output
void output(SqList L)
{
int i=1 ;
while (i<=L.length);
{
printf("%-5d %13s %10d \n",L.student[i-1].num, L.student[i-1].name, L.student[i-1].score);
i++;
}
}
//main
int main(int argc, char* argv[])
{
SqList L ;
initList(L);
input(L);
output(L);
return 0;
}
//main 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询