请帮我看下,哪里出错了?能否帮我写出正确的!

来源:百度知道 编辑:UC知道 时间:2024/06/14 18:08:48
#include "stdio.h"
#define SIZE 1400
long readstockcode();
void main()
{
int i;
long stockcode[SIZE];
long code;
code=readstockcode();
while(code!=-1)
{
stockcode[i]=code;
code=readstockcode();
}
}
long readstockcode()
{

long stockcode;
scanf("%ld",&stockcode);
printf("%ld\n",stockcode);
return stockcode;
}

正确的如下:
#include <stdio.h>

#define SIZE 1400

long readstockcode()
{
long stockcode;

scanf("%ld",&stockcode);
printf("%ld\n",stockcode);
return stockcode;
}

void main()
{
long stockcode[SIZE];
long code;
int i=0;

code=readstockcode();
while(code!=-1)
{
stockcode[i]=code;
code=readstockcode();
i=(i+1)%SIZE;
}
}