- 论坛徽章:
- 0
|
要求的功能是向顺序表中输入数据,然后再将其中的数据打印出来,但运行结果有问题。
这是运行过程Please input elem 1 of Sq_list:1
2
Please input elem 2 of Sq_list:3
Please input elem 3 of Sq_list:4
Please input elem 4 of Sq_list:5
Please input elem 5 of Sq_list:6
You've entered:
1 2 3 4 5
在输入第一个数据之后怎么没有马上出来输入第二个数据的提示呢?而是要再输入一个数据。
这是源程序#include <stdio.h>;
#include <stdlib.h>;
#define OVERFLOW -2
#define OK 1
#define LIST_INIT_SIZE 100 /* 线性表存储空间的初始分配量 */
#define LISTINCREMENT 10 /* 线性表存储空间的分配增量 */
typedef int Status; /* Status 是函数的返回状态码 */
typedef int ElemType;
typedef struct {
ElemType *elem; /* 存储空间基址 */
int length; /* 当前长度 */
int listsize; /* 当前分配的存储容量 */
}SqList;
/* 构造一空的线性表 */
Status InitList_Sq(SqList *L)
{
L->;elem = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if (L->;elem == NULL)
exit(OVERFLOW);
L->;length = 0;
L->;listsize = LIST_INIT_SIZE;
return OK;
}
int main()
{
SqList *L1, list;
int i;
L1=&
if (InitList_Sq(L1)) {
for (i = 0;i < 5;i++) {
fprintf(stdout, " lease input elem %d of Sq_list:", i+1);
fscanf(stdin, "%d\n", L1->;elem);
++L1->;elem;
++L1->;length;
}
} else {
fprintf(stdout, "List is not initialized.\n" ;
exit(OVERFLOW);
}
L1->;elem -= L1->;length; /* 将elem回指到头元素 */
if (L1->;elem != NULL && L1->;length != 0) {
fprintf(stdout, "You've entered:\n" ;
for (i = 0;i < L1->;length;i++) {
fprintf(stdout, "%d\t", *(L1->;elem));
++L1->;elem;
}
fprintf(stdout, "\n" ;
}
return 0;
} |
|