我需要指定一个包含300000个数据的字符数组,这个数组是从包含以列格式(其庞大的数据文件)排列的200,000个数字的Numbers.dat文件中获取的。操作是从该文件中提取数据并将其存储在300000的数组中,以便将这些300000数字再次存储在不同的文件中。此操作针对两个文件执行,因此这两个文件的子集的形式为错误数组大小
-0.98765
-0.124567
etc 但我得到两个错误:首先是语法错误,说数组大小太长,另一个是逻辑错误。如何解决这个问题。该代码是如下由枪手在How to read blocks of numbers from a text file in C提供,但不用于这种情况下
#include <stdio.h>
#include<stdlib.h>
# include <conio.h>
# include <dos.h>
# include <math.h>
void main()
{ FILE *fpt1,*fpt2,*fpt;
fp=fopen("numbers.dat","r");
fpt1=fopen("subset1.dat","w");
fpt2=fopen("subset2.dat","w");
int index=0;
char anum[300000]; //this is the reason for the first syntactic error :Array size too large
// since we are not calculating, we can store numbers as string
while(fscanf(fp,"%s",anum) == 1)
{
if(index==0)
{
// select proper output file based on index.
fprintf(fpt1,"%s",anum);
index++; }
if(index ==300000)
{
fprintf(fpt2,"%s",anum);
index++; }
}
fclose(fp);
fclose(fpt1);
fclose(fpt2);
}
逻辑错误是,只有一个号码被写入在文件SUBSET1和SUBSET2甚至当我减小尺寸至300块时的工作数据的。
请显示您的代码? – 2011-03-11 08:34:58
哪个来源?哪个编译器?哪个命令行?哪个错误信息?如何以智能的方式提出问题:http://www.catb.org/~esr/faqs/smart-questions.html – DevSolar 2011-03-11 08:36:03
@To all:我有TURBO C++ FOR WINDOWS 4.5。 – SKM 2011-03-11 08:50:12