- 论坛徽章:
- 0
|
#include <string.h>
#include<stdlib.h>
#include<stdio.h>
void tst_fun(double val)
{
printf("%.2lf\n",val);
}
int main(int argc, char** argv)
{
double iVal;
char* pindex;
FILE* pf = fopen("e:\\a.txt","rb");
if(pf == NULL)
{
//err_handle();
return (1);
}
const int BUFFLEN=200;
char buffer[BUFFLEN];
while(!feof(pf)) //判断是否到了文件末尾
{
//读取一行文件内容
fgets(buffer,BUFFLEN,pf);
//handle stream
pindex = strstr(buffer,":");
if (NULL == pindex)
{
pindex = strstr(buffer,":");
if (NULL != pindex)
{
pindex++;
}
}
while (NULL != pindex)
{
pindex++;
iVal = atof(pindex);
//call function
tst_fun(iVal);
if (NULL == strstr(pindex,":"))
{
pindex = strstr (pindex, ":");
if (NULL != pindex)
pindex++;
}
else
{
pindex = strstr (pindex, ":");
}
}
}
fclose(pf);
return 0;
}
大家帮我改改这个代码好吗?我想将文件里面每一行冒号后面的数据读出来,然后赋值给每一个我设定的未知数,
"输出:X1=
X2=
X3=
X4=
........"
数据有很多,有些麻烦,哪位大侠能帮小弟改改? |
|