Visual C ++使用scanf从文本文件中读取数据 [英] Visual C++ reading data from text file using 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" "%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屋!
推荐答案