MFC对txt文件操作问题
部分原始数据是这样的:-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 690 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999
最后要变成的格式为:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
.......
......
也就是一行有十个
编写的代码如下:
得不出答案,求指教
void CProcedureViewView::OnInputData()
{
// TODO: Add your command handler code here
CProcedureDoc*pDoc=GetDocument();
FILE*file;
file=fopen("data).txt","r");
for(int i=0;i<241;i++) //地形数据的行数
{
for(int j=0;j<135;j++) //地形数据的列数
{
fscanf(file,"%f",&nodexyz[i][j]); //nodexyz[i][j]为存储地形数据的变量
}
}
fclose(file);
}
void CProcedureViewView::OnOnOutputData()
{
// TODO: Add your command handler code here
CProcedureDoc*pDoc=GetDocument();
int i,j,k;
k=0;
int len;
CString str;
FILE*pfile=fopen("dataout.txt","w");
for(i=0;i<241;i++)
for(j=0;j<135;j++)
{
if(nodexyz[i][j]==-9999)
{
xinodexyz[k]=0; //将没有实际高程值处的高程值由原来的一9999改为0
}
else
xinodexyz[k]=nodexyz[i][j];
k++;
}
for(i=0;i<691380;i++)
{
str.Format("%12.2f\t",xinodexyz[i]);
if(i%10==0)
{
str+="\n";
}
len=strlen(str);
fwrite(str,1,len,pfile);
}
fflush(pfile);
}