Visual C ++使用scanf从文本文件中读取数据 [英] Visual C++ reading data from text file using scanf

查看:237
本文介绍了Visual C ++使用scanf从文本文件中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


以下代码未从bn1.txt读取数据

following code is not reading data from bn1.txt

FILE * gdata;

FILE *gdata;

gdata = fopen(

gdata=fopen(

" ; bn1.txt" " r" );

"bn1.txt","r");

fscanf(gdata,

fscanf(gdata,

< span style ="co LOR:#a31515; font-size:small"> "%d \ n" ,& m1);

"%d\n",&m1);

for (n = 0; n< ; m1; n ++){

for( n=0;n<m1;n++) {

fscanf(gdata,

fscanf(gdata,

"%f %f%f \ n" ,& x1 [n ],& y1 [n],& z1 [n]);

"%f %f %f\n",&x1[n],&y1[n],&z1[n]);

printf(

"%f%f%f \ n" ,x1 [n],y1 [n],z1 [n]);

"%f %f %f\n",x1[n],y1[n],z1[n]);

  }

fclose(gdata);

fclose(gdata);

推荐答案

什么是fscanf返回?

What is fscanf returning?

此外,每当您使用fscanf读取换行符时,请尝试执行fflush。有时新行会卡住,你需要刷新输入缓冲区才能继续阅读。

Also, whenever you read a newline using fscanf try doing an fflush. Sometimes the newline gets stuck and you need to flush the input buffer to continue reading.


这篇关于Visual C ++使用scanf从文本文件中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆