使用fscanf时出现问题 [英] Problem in using fscanf

查看:118
本文介绍了使用fscanf时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,


我写了一个代码,假设读取了十六进制
文件中的所有数字,但令我惊讶的是代码是每个替代价值都要划掉。不要吗?b $ b知道为什么吗?


你能帮我解决这个问题。


代码如下;

main()

{

FILE * fdataptr;

int x;

int ctrl;

x = 1;


//打开包含数据的文件

fdataptr = fopen(" data.txt"," r");

if(fdataptr == NULL){

printf(" \ n无法打开文件data.txt");

退出(1);

}


做{

fscanf(fdataptr,"%x",& ctrl);

printf(" \ n \ nn data is 0x%x \ n\ n",ctrl );

if(fscanf(fdataptr,"%x",& ctrl)== EOF)

break;

} while (x);


}

data.txt有值得


11111111

22222222

33333333

44444444

55555555

66666666

77777777

88888888

99999999


谢谢&此致,

RSK ...

Hi Friends,

I have written a code which suppose to read all the numbers from a hex
file,But to my surprise the code is skiping every alternate value.Don''t
know why?

Can you please help me in solving this problem.

The code is as follows;
main ()
{
FILE *fdataptr;
int x;
int ctrl;
x=1;

// Open the file containing data
fdataptr = fopen("data.txt", "r");
if(fdataptr==NULL){
printf("\n Cannot open File data.txt");
exit(1);
}

do {
fscanf(fdataptr,"%x", &ctrl);
printf ("\n\n data is 0x%x \n\n",ctrl);
if (fscanf(fdataptr,"%x", &ctrl)==EOF)
break;
} while (x);

}
data.txt is having the values

11111111
22222222
33333333
44444444
55555555
66666666
77777777
88888888
99999999


Thanks & Regards,
RSK...

推荐答案

rsk写道:
rsk wrote:

嗨朋友们,


我写了一个代码,假设从十六进制读取所有数字

文件,但是令我惊讶的是,代码正在掠过每一个替代值。不是吗?b $ b知道为什么?
Hi Friends,

I have written a code which suppose to read all the numbers from a hex
file,But to my surprise the code is skiping every alternate value.Don''t
know why?



因为你读取并忽略每一个数字?

[snip]

Because you read and ignore every second number?
[snip]


do {

fscanf(fdataptr,"%x",& ctrl);

printf(" \ n \ n数据为0x%x \ n \\ nn,ctrl;

if(fscanf(fdataptr,"%x",& ctrl)== EOF)

break;

} while(x);
do {
fscanf(fdataptr,"%x", &ctrl);
printf ("\n\n data is 0x%x \n\n",ctrl);
if (fscanf(fdataptr,"%x", &ctrl)==EOF)
break;
} while (x);


你能否纠正我打印所有数据值

Can you correct me to print all the data values


rsk写道:
rsk wrote:

你能纠正我打印所有数据的价值
Can you correct me to print all the data values



当你是回复。


我不打算为你纠正你的程序。我已经告诉过你

你做错了什么,我认为现在由你来纠正它。

Please quote some context when you are replying.

I''m not going to correct your program for you. I''ve already told you
what you are doing wrong, and I think it''s now down to you to correct it.


这篇关于使用fscanf时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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