C语言从文件中读取数据的问题

写一个c语言程序,其中必须包含下列代码:
float a,b;
int i,j;
char c1,c2,c3;
int Retcode;
Retcode=fscanf(stdin,"%o 2%ld %c 5%c %c %f %f",
&i,&j,&c1,&c2,&c3,&b,&a);
要从一个文件,Text2.in中读取数据
Text2.in的内容如下:
***77**243567\n
*2.4e3**14.7\n
172**\n
其中*号是空格,
要求得到i,j,c1,c2,c3,b,a,Retcode这几个变量的值?
我写的代码是:

This is a part of a program:
float a,b;
int i,j;
char c1,c2,c3;
int RetCode;
RetCode=fscanf(stdin," %o 2%ld %c 5%c %c %f %f ",&i,&j,&c1,&c2,&c3,&b,&a);

i need use this program to read some information from a file which named "Text2.in",
i am going to show you what's in the file "Text2.in"
***77**243567\n
*2.4e3 14.7\n
172**\n

i used * replace blank,in reality they are blanks

and the question is what's the value of Retcode,a,b,i,j,c1,c2,c3????

now i am going to show you my program

#include<stdio.h>
#include<stdlib.h>
int main(void)
{
float a,b;
int i,j;
char c1,c2,c3;
int Retcode;
FILE*fp;
stdin = fopen("Text2.in","r");
Retcode=fp(stdin,"%o 2%ld %c 5%c %c %f %f", &i,&j,&c1,&c2,&c3,&b,&a);
system("pause");
return 0;
}
不知道对不对,帮忙看一下.
值我运行完程序都知道了,大家也不用告诉我,只是不知道程序是怎么读的,希望可以解说一下?还有为什么Retcode的值为3?

我如果把代码改成这样的话:
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
float a,b;
int i,j;
char c1,c2,c3;
int Retcode;
FILE*stdin;
stdin = fopen("Text2.in","r");
Retcode=fscanf(stdin,"%o 2%ld %c 5%c %c %f %f", &i,&j,&c1,&c2,&c3,&b,&a);
system("pause");
return 0;
}
就会报错了,就是把原来fp的地方换成stdin,不能运行,为什么?希望高手可以说下stdin是什么?

希望大家认真看完,帮忙解答下每个问题,对我非常重要!!谢谢

第1个回答  2019-10-04
c语言读取文件中的txt数据,参考代码如下:
读文件中的txt数据:
#include
#include
void main()
{
file* emfile = fopen("d://emfile.txt","r");
if (!emfile) {
cout<<"file not found!";
return;
}
int xn=2;//假设文件有两行,三列
int yn=3;
float** ef;
ef = new float*[xn];
for(int idx=0;idx
评论
0
0
加载更多
第2个回答  2009-10-07
stdin是FILE指针,不需要用fopen打开,因为系统在开始执行你的main函数之前就先替你打开了。
目前还没有弄明白Retcode为啥是3,貌似删掉第二行14.7以后的东西,最后得到的也是3,把第二、三行整个删掉,就变成2了本回答被提问者采纳
第3个回答  2009-10-11
二楼正解
相似回答