免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1362 | 回复: 2
打印 上一主题 下一主题

帮我看看这个顺序表的程序怎么了? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-07-07 12:48 |只看该作者 |倒序浏览
要求的功能是向顺序表中输入数据,然后再将其中的数据打印出来,但运行结果有问题。
这是运行过程
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;
}

论坛徽章:
0
2 [报告]
发表于 2005-07-07 13:28 |只看该作者

帮我看看这个顺序表的程序怎么了?

fscanf语句改为:
      fscanf(stdin, "%d", L1->;elem);
  去掉"\n"

论坛徽章:
0
3 [报告]
发表于 2005-07-07 13:37 |只看该作者

帮我看看这个顺序表的程序怎么了?

原帖由 "wgbljl" 发表:
fscanf语句改为:
      fscanf(stdin, "%d", L1->;elem);
  去掉"\n"


多谢啊,解决了。看来还是c的基础不过关,得再看一遍the c programming language了,呵呵。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP