LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 673|回复: 4

大家看一下下面的这个函数在输入上为什么不正确?

[复制链接]
发表于 2003-9-11 15:21:17 | 显示全部楼层 |阅读模式
[PHP]List Insert_List(List L)
{
    int i;
    ElemType value;
    ElemType *newbase,*q,*p;
    printf("lease Input The Insert Number And Value: ");
    while(2 != scanf("%d%d",&i,&value)) continue;
    if(i<1 || i>L.length+1) exit(1);
    if(L.length>=L.listsize){
        newbase=(ElemType *) realloc(L.elem,
                (L.listsize+LISTINCREMENT) * sizeof(ElemType));
        if (!newbase) exit(1);
        L.elem=newbase;
        L.listsize+=LISTINCREMENT;
    }
   q=&(L.elem[i-1]);
   for (p=&(L.elem[L.length-1]);p>=q; --p)
       *(p+1) = *p;
   *q = value;
   ++L.length;
   printf("The Value %d Had Insert\n",value);
   printf("The List Value:\n");
   while(getchar()) continue;
   Display_List(L);
   return L;
}

[/PHP]

我一输入两个整数,就会结束程序,不知道为什么! ElemType 为   int 型!
 楼主| 发表于 2003-9-11 15:22:26 | 显示全部楼层
[PHP]typedef int ElemType;
typedef struct
{
    ElemType *elem;  /*存储空间基址*/
    int length;      /*当前长度*/
    int listsize;    /*当前分配的存储容量*/
}List;
[/PHP]
 楼主| 发表于 2003-9-12 09:08:35 | 显示全部楼层
没有人回答???
发表于 2003-9-12 09:33:00 | 显示全部楼层
在printf("lease Input The Insert Number And Value: ");

和    while(2 != scanf("%d%d",&i,&value)) continue;之间应该调用屏幕接收函数fgets()吧,否则你输入的参数进不来吧.
发表于 2003-9-12 12:08:09 | 显示全部楼层
自己使用gdb跟看呢
不就知道哪里有问题了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表