首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

内存不能被写咋回事

2012-09-14 
内存不能被写怎么回事?//线性表的顺序存储结构#includestdio.h#includemalloc.h#define ListSize 100t

内存不能被写怎么回事?
//线性表的顺序存储结构
#include<stdio.h>
#include<malloc.h>
#define ListSize 100
typedef int DataType;
typedef struct{
DataType data[ListSize];
int length;
}SeqList;
#define N 8
#define Error printf
void InsertList(SeqList* L);
void DeleteList(SeqList* L);
int main()
{
SeqList* L;
int i;
char c;
printf("请按递减输入%d个整数(以空格为间隔):",N);
for(i=0;i<N;i++)
{
scanf("%d",&L->data[i]);
}
L->length = N;
printf("请选择:\n");
printf("A-------------------插入--------------\n");
printf("B-------------------删除--------------\n");
printf("C-------------------退出--------------\n");
scanf("%c",&c);
while(c!='c'||c!='C')
{
if(c=='a'||c=='A')
InsertList(L);
else if(c=='b'||c=='B')
DeleteList(L);
scanf("%c",&c);
}
return 0;
}

void InsertList(SeqList* L)
{
int key,i,c,d;
printf("请输入要插入的整数值:");
scanf("%d",&key);
printf("你将在下列序列中插入%d\n",key);
for(i=0;i<L->length;i++)
{
printf("%3d",L->data[i]);
}
i=0;
while(i<L->length)
{
if(key == L->data[i])
{
Error("重复插入,插入失败!\n");
}
else if(L->length >=ListSize)
{
Error("表长度溢出!\n");
}
else
{
for(c=0;c<L->length;c++)
{
if(key > L->data[c])
{
break;
}
}
for(d=L->length;d>=c;d--)
{
L->data [d+1] = L->data[d];
}
L->data[c]=key;
L->length++;
}
}

}

void DeleteList(SeqList* L)//删除还没有实现呢
{

}
//当输入8个整形数据时 在按回车键就提示内存不能被写怎回事啊

[解决办法]
没有分配内存

C/C++ code
#includ
[解决办法]
ls说对了,用数组也是可以的
[解决办法]
肯定是内存没有管理好。。。如ls的,内存没有分配
[解决办法]
C/C++ code
#include<stdio.h>#include<malloc.h>#define ListSize 100typedef int DataType;typedef struct{DataType data[ListSize];int length;}SeqList;#define N 8#define Error printfvoid InsertList(SeqList* L);void DeleteList(SeqList* L);int main(){    SeqList* L;    L = (SeqList *)malloc(sizeof(SeqList));    int i;    char c;    printf("请按递减输入%d个整数(以空格为间隔):",N);    for(i=0;i<N;i++)    {        scanf("%d",&L->data[i]);    }    L->length = N;    printf("请选择:\n");    printf("A-------------------插入--------------\n");    printf("B-------------------删除--------------\n");    printf("C-------------------退出--------------\n");    scanf("%c",&c);    while(c!='c'||c!='C')    {        if(c=='a'||c=='A')            InsertList(L);        else if(c=='b'||c=='B')            DeleteList(L);        scanf("%c",&c);    }    return 0;}void InsertList(SeqList* L){    int key,i,c,d;    printf("请输入要插入的整数值:");    scanf("%d",&key);    printf("你将在下列序列中插入%d\n",key);    for(i=0;i<L->length;i++)    {        printf("%3d",L->data[i]);    }    i=0;    while(i<L->length)    {        if(key == L->data[i])        {            Error("重复插入,插入失败!\n");        }        else if(L->length >=ListSize)        {            Error("表长度溢出!\n");        }        else        {            for(c=0;c<L->length;c++)            {                if(key > L->data[c])                {                    break;                }            }            for(d=L->length;d>=c;d--)            {                L->data [d+1] = L->data[d];            }            L->data[c]=key;            L->length++;        }    }}void DeleteList(SeqList* L)//删除还没有实现呢{} 


[解决办法]
没有分配啊!!
检查检查吧!!

热点排行