为什么这个程序可以通过编译,却不能执行呢, 能给我点指点吗?
#include <stdio.h>#include <stdlib.h>
#define FALSE -1
#define TURE 0
#define Max_size 30
#define LIST_INIT_SIZE 10
typedef int ElemType;
typedef struct
{
ElemType pBase[Max_size];
int nLength;
int nSize;
}SqList;
int InitList(SqList *pList) /*线性表初始化*/
{
pList = (SqList *) malloc(sizeof (SqList));
pList -> nLength = 0;
pList -> nSize = Max_size;
return TURE;
}
void DestroyList(SqList *pList) /*销毁线性表*/
{
free(pList);
}
int ListLength(SqList *pList) /*线性表的长度*/
{
return (pList -> nLength);
}
int ListEmpty(SqList *pList) /*判断线性表是否为空*/
{
if (pList -> nLength == 0)
return FALSE;
else
return TURE;
}
int ShowList(SqList *pList) /*输出线性表*/
{
int pos, n = 0;
if (ListEmpty (pList))
return FALSE;
for (pos = 0; pos < pList -> nLength; pos++)
{
printf ("%d ", pList -> pBase[pos]);
n++;
if (n % 5 == 0)
printf ("\n");
}
printf ("\n");
}
int GetElem(SqList *pList, int pos, int e) /*求线性表中某个元素的值*/
{
if (pos < 1 || pos > pList -> nLength)
return FALSE;
else
e = pList -> pBase [pos - 1];
return TURE;
}
int LocateElem(SqList *pList, int e) /*查找元素e*/
{
int pos;
for (pos = 0; pos < pList -> nLength && pList -> pBase[pos] != e;)
pos++;
if (pos >= pList -> nLength)
return FALSE;
else
return (pos + 1);
}
int ListDelete(SqList *pList, int pos, int e) /*删除数据元素*/
{
int j;
if (pos < 1 || pos > pList -> nLength)
return FALSE;
pos--;
e = pList -> pBase[pos];
for (j = pos; j < pList -> nLength - 1; j++)
{
pList -> pBase[j] = pList -> pBase[j + 1];
}
pList -> nLength--;
return TURE;
}
int ListInsert(SqList *pList, int pos, int e) /*插入数据元素*/
{
int j;
if (pos < 1 || pos > pList -> nLength)
return FALSE;
pos--;
for (j = pList -> nLength; j > pos; j--)
{
pList -> pBase[j] = pList -> pBase[j - 1];
}
pList -> pBase[pos]= e;
pList -> nLength++;
return TURE;
}
int ReadList(SqList *pList,int n) /*从文件读入n(n > 10)个整数,填入顺序表*/
{
int i;
FILE * fp = fopen("list.txt","r");
if (fp == NULL)
{
printf ("错误!无法读入文件!");
exit(0);
}
for(i = 0; i < n; i++)
fscanf(fp,"%d ",&pList -> pBase[i]);
pList -> nLength = n;
fclose(fp);
return TURE;
}
int SaveList(SqList *pList) /*将线性表保存到文件中*/
{
FILE *fp;
int i;
fp=fopen("list.txt","r+");
for(i = 0;i < pList -> nLength; i++)
fprintf(fp,"%d ", pList -> pBase[i]);
fclose(fp);
return TURE;
}
int main()
{
int n, e1, e2;
SqList *pList;
printf ("(1).初始化线性表\n");
InitList (pList);
printf ("请输入n的值: ");
scanf ("%d", &n);
ReadList(pList, n);
printf ("\n");
printf ("(2).输出%d个数至屏幕\n", n);
ShowList(pList);
printf ("(3).查找元素的位序\n");
printf ("元素7的位序为%d\n", LocateElem(pList, 7));
printf ("\n");
printf ("(4).在顺序表头、中、尾各插一个元素\n");
ListInsert(pList, 1, 1);
ListInsert(pList, 9, 8);
ListInsert(pList, 17, 15);
ShowList(pList);
printf ("\n");
printf ("(5).输入修改后的表至屏幕,并保存至文件\n");
ShowList(pList);
SaveList(pList);
printf ("\n");
/*printf ("(6).删除顺序表的任意两个元素\n");
ListDelete(pList, 5, e1);
ListDelete(pList, 11, e2);*/
DestroyList(pList);
system("pause");
}