fscanf不能使用%.3f %.3lf 吗
fprintf使用%.3f写入,fscanf使用%.3f读出的确实0,为什么?代码如下
我把读取错误的那一行注释掉了
#include <QtCore/QCoreApplication>
//#include <sys
int main(int argc, char *argv[])
{
QCoreApplication window(argc, argv);
char s[10]={'\0'};
int a =12;
float b =123.456,f = 0.0,g= 0.0;
int c = 0,d =0;
FILE *fp = fopen("f:\\xx\\visual studio 2010\\file.txt", "w") ;
fprintf(fp,"%3d:%d\n",a,a);
fprintf(fp,"%.3f:%f",b,b);
fclose(fp);
fp = fopen("f:\\xx\\visual studio 2010\\file.txt", "r");
fscanf(fp,"%3d:%d",&c,&d);
//fscanf(fp,"%.3f:%f",&f,&g);
fscanf(fp,"%f:%f",&f,&g);
printf("%3d:%d\n",c,d);
printf("%5.3f:%f\n",f,g);
fclose(fp);
system("pause");
return window.exec();
}
[解决办法]
一直没有这种用法吧?
http://www.cplusplus.com/reference/cstdio/fscanf/