在用C写结构数组的时候,返回值的时候出现了问题
代码:#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct List{
int *elem;
int length;
int listsize;
}List;
List L;
void InitList()
{
L.elem =(int *)malloc(LIST_INIT_SIZE *sizeof(int));
if (!L.elem)exit(OVERFLOW);
L.length = 0;
L.listsize = LIST_INIT_SIZE;
/*if (L.length =L.listsize){
int newbase = (int *)realloc(L.elem,(L.listsize+ LISTINCREMENT)*sizeof(int));
if(!newbase)exit(OVERFOW);
L.elem = newbase;
L.listsize += LISTINCREMENT;
}
int q = L.elem;
if(int i = 0; i<n;i++)
{
q++;
scanf("%d",&q);
}*/
return OK;
}
void Input(List &L)/*出错的地方*/
{
int e , flag = 1;
while(flag)
{
printf("输入数据(整数),以-1结束输入:");
scanf("%d",&e);
if( e==-1)
{
flag=0;
}
else
{
L.elem [L.length ]=e;
L.length++;
}
if(f.length >=f.listsize )
{
int *newbase=(int *)realloc(L.elem ,(L.listsize +LISTINCREMENT)*sizeof(int));
L.elem =newbase;
L.listsize +=LISTINCREMENT;
}
}
}
void print(List L)
{
int i=0,j;
j=L.length ;
printf("表中元素:");
while(i<j)
{
printf("%d",L.elem[i]);
i++;
printf(",");
}
printf("\n");
}
main()
{
InitList(L);
Input();
print(L);
}
错误信息:
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test1.c
F:\作业习题\数据结构\习题\test\test1.c(36) : warning C4098: 'InitList' : 'void' function returning a value
F:\作业习题\数据结构\习题\test\test1.c(38) : error C2143: syntax error : missing ')' before '&'
F:\作业习题\数据结构\习题\test\test1.c(38) : error C2143: syntax error : missing '{' before '&'
F:\作业习题\数据结构\习题\test\test1.c(38) : error C2059: syntax error : '&'
F:\作业习题\数据结构\习题\test\test1.c(38) : error C2059: syntax error : ')'
F:\作业习题\数据结构\习题\test\test1.c(80) : warning C4013: 'Input' undefined; assuming extern returning int
执行 cl.exe 时出错.
test.exe - 1 error(s), 0 warning(s)
[解决办法]
return OK; void 哪来return?