我这里编一个程序,想从一个文本文件中读出数据
文件格式如下
1,22227
2,-3145
3,23447
4,……
……
依次类推
下面是我的代码,运行时会出错,
Expression: str!=NULL
其中str是CString,
---------------函数的代码如下
int play(CString m_input,CString m_output)
{
CStdioFile fr;
fr.Open(m_input,CFile::modeRead);
FILE *fw=fopen(m_output,"wt");
CString str="1,222";
double t[i],a[1000];
int i=0;
::AfxMessageBox("Okay");
if(str!=NULL)
{
while(fr.ReadString(str))
{
sscanf(str,"%lf,%lf",&t[i],&a[i]);
fprintf(fw,"%lf\n",a[i]);
i++;
}
}
fclose(fw);
fr.Close();
return 1;
}
----------------------------------------------------
多谢多谢阿
应该是double t[1000],a[1000];
而非double t[i],a[1000];
FILE *txt_file = _tfopen(file_name,_T("r"));
if (txt_file == NULL)
{
return;
}
while(_fgetts(buff,sizeof(buff),txt_file))
{
}
find.Close();
不过我想明白为什么我的程序有错误阿
我把我修改后的在写上,还是那个错误,要命拉
----------------------
int play(CString m_input,CString m_output)
{
CStdioFile fr;
fr.Open(m_input,CFile::modeRead);
FILE *fw=fopen(m_output,"wt");
CString str;
double t,a[1000];
int i=0;
::AfxMessageBox("Okay"); while(fr.ReadString(str))
{
::AfxMessageBox(str); sscanf(str,"%lf,%lf",&t,&a[i]);
fprintf(fw,"%lf\n",a[i]);
i++;
}
fclose(fw);
fr.Close();
return 1;
}