fscanf挂起 [英] fscanf hangs

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

问题描述

我在Windows XP 5.1(SP2)上使用MS Visual C ++ 6.0。


我不确定这是C,C ++还是MS问题,但fscanf已经

随机挂在我身上。我打电话数百,如果不是数千,

次,但它挂在不同的地方,使用相同的数据。

违规代码如下。


ReadFile(char * csFileName)

{

float fFloat1 ,fFloat2;

long lLong1,lLong2,lNum,lLastX = iColumns-1,lLastY = iRows-1;

int iRead;

FILE * fpInFile;


if((fpInFile = fopen(csFileName," r"))== NULL)return

ErrorOpeningFile(csFileName);


do

{

//随机挂在以下



iRead = fscanf(fpInFile,"%d%d%f%f%d"& lLong1,& lLong2,& fFloat1,

& fFloat2,& lNum );

if(iRead == 0 || iRead == EOF)break;

} while(lX< lLastX || lY< lLastY);

}


我想知道我是否应该只进行二进制读取,以便对发生的事情有更多的控制权。 br />

非常感谢任何协助,

彼得。

解决方案

6月18日上午10点19分,PeterOut< MajorSetb ... @ excite.comwrote:


我在Windows XP 5.1上使用MS Visual C ++ 6.0 (SP2)。


我不确定这是否是C,C ++或MS问题,但fscanf随机挂在我身上。我打电话数百,如果不是数千,

次,但它挂在不同的地方,使用相同的数据。

违规代码如下。


ReadFile(char * csFileName)

{

float fFloat1 ,fFloat2;

long lLong1,lLong2,lNum,lLastX = iColumns-1,lLastY = iRows-1;

int iRead;

FILE * fpInFile;


if((fpInFile = fopen(csFileName," r"))== NULL)return

ErrorOpeningFile(csFileName);


do

{

//随机挂在以下



iRead = fscanf(fpInFile,"%d%d%f%f%d"& lLong1,& lLong2,& fFloat1,

& fFloat2,& lNum );

if(iRead == 0 || iRead == EOF)break;

} while(lX< lLastX || lY< lLastY);


}


我想知道我是否应该只做二进制阅读以便有更多

控制o发生了什么事。


非常感谢您的任何帮助,

彼得。



亲爱的Peter,


您没有关闭文件。

使用fclose关闭文件。


谢谢和问候,

Amal P.


On Jun 17,9:32 pm,Amal P< enjoyam ... @ gmail.comwrote:


6月18日上午10点19分,PeterOut< MajorSetb ... @ excite.comwrote:


我在Windows XP 5.1(SP2)上使用MS Visual C ++ 6.0。


我不确定这是否是C,C ++或MS问题但是fscanf已经随机挂在我身上了
。我打电话数百,如果不是数千,

次,但它挂在不同的地方,使用相同的数据。

违规代码如下。


ReadFile(char * csFileName)

{

float fFloat1,fFloat2;

long lLong1,lLong2,lNum,lLastX = iColumns-1,lLastY = iRows-1;

int iRead;

FILE * fpInFile;


if((fpInFile = fopen(csFileName," r"))== NULL)return

ErrorOpeningFile( csFileName);


do

{

//随机挂在下面

line

iRead = fscanf(fpInFile,"%d%d%f%f%d",& lLong1,& lLong2,& fFloat1,

& fFloat2,& lNum);

if(iRead == 0 || iRead == EOF)break;

} while(lX< lLastX || lY< lLastY);


}


我想知道我是否应该只做二进制阅读以便更多地控制正在发生的事情。


非常感谢您的任何帮助,

彼得。



亲爱的彼得,


您没有关闭文件。

使用fclose关闭文件。


谢谢和问候,

Amal P.-隐藏引用文字 -


- 显示引用text -



对不起。我正在关闭文件

fclose(fpInFile);

但忘记在我发布的示例代码中包含它。

问题,不合时宜地在其他地方。


谢谢,

彼得。




" PeterOut" < Ma ********** @ excite.com写信息

新闻:11 ******************** **@c77g2000hse.googlegr oups.com ...


>我在Windows XP 5.1(SP2)上使用MS Visual C ++ 6.0。


我不确定这是C,C ++还是MS的问题,但是fscanf已经随机挂在我身上了。我打电话数百,如果不是数千,

次,但它挂在不同的地方,使用相同的数据。

违规代码如下。


ReadFile(char * csFileName)

{

float fFloat1 ,fFloat2;

long lLong1,lLong2,lNum,lLastX = iColumns-1,lLastY = iRows-1;

int iRead;

FILE * fpInFile;


if((fpInFile = fopen(csFileName," r"))== NULL)return

ErrorOpeningFile(csFileName);


do

{

//随机挂在以下



iRead = fscanf(fpInFile,"%d%d%f%f%d"& lLong1,& lLong2,& fFloat1,

& fFloat2,& lNum );



%d用于类型''int''。对于''long''类型,使用%ld。


还要确保你已经#include< stdio.h为

声明' 'fscanf()''。


-Mike


I am using MS Visual C++ 6.0 on Windows XP 5.1 (SP2).

I am not sure if this is a C, C++ or MS issue but fscanf has been
randomly hanging on me. I make the call hundreds, if not thousands,
of times but it hangs in different places with the same data. The
offending code follows.

ReadFile(char *csFileName)
{
float fFloat1, fFloat2;
long lLong1, lLong2, lNum, lLastX = iColumns-1, lLastY =iRows-1;
int iRead;
FILE *fpInFile;

if ((fpInFile= fopen(csFileName, "r")) == NULL) return
ErrorOpeningFile(csFileName);

do
{
// It randomly hangs on the followinf
line
iRead=fscanf(fpInFile, "%d%d%f%f%d", &lLong1, &lLong2, &fFloat1,
&fFloat2, &lNum);
if (iRead==0 || iRead==EOF) break;
} while (lX < lLastX || lY < lLastY);
}

I am wondering if I should just do binary reading so as to have more
control over what is going on.

Many thanks in advance for any assistance,
Peter.

解决方案

On Jun 18, 10:19 am, PeterOut <MajorSetb...@excite.comwrote:

I am using MS Visual C++ 6.0 on Windows XP 5.1 (SP2).

I am not sure if this is a C, C++ or MS issue but fscanf has been
randomly hanging on me. I make the call hundreds, if not thousands,
of times but it hangs in different places with the same data. The
offending code follows.

ReadFile(char *csFileName)
{
float fFloat1, fFloat2;
long lLong1, lLong2, lNum, lLastX = iColumns-1, lLastY =iRows-1;
int iRead;
FILE *fpInFile;

if ((fpInFile= fopen(csFileName, "r")) == NULL) return
ErrorOpeningFile(csFileName);

do
{
// It randomly hangs on the followinf
line
iRead=fscanf(fpInFile, "%d%d%f%f%d", &lLong1, &lLong2, &fFloat1,
&fFloat2, &lNum);
if (iRead==0 || iRead==EOF) break;
} while (lX < lLastX || lY < lLastY);

}

I am wondering if I should just do binary reading so as to have more
control over what is going on.

Many thanks in advance for any assistance,
Peter.

Dear Peter,

Your are not closing the file.
Use fclose for closing the file.

Thanks and regards,
Amal P.


On Jun 17, 9:32 pm, Amal P <enjoyam...@gmail.comwrote:

On Jun 18, 10:19 am, PeterOut <MajorSetb...@excite.comwrote:


I am using MS Visual C++ 6.0 on Windows XP 5.1 (SP2).

I am not sure if this is a C, C++ or MS issue but fscanf has been
randomly hanging on me. I make the call hundreds, if not thousands,
of times but it hangs in different places with the same data. The
offending code follows.

ReadFile(char *csFileName)
{
float fFloat1, fFloat2;
long lLong1, lLong2, lNum, lLastX = iColumns-1, lLastY =iRows-1;
int iRead;
FILE *fpInFile;

if ((fpInFile= fopen(csFileName, "r")) == NULL) return
ErrorOpeningFile(csFileName);

do
{
// It randomly hangs on the followinf
line
iRead=fscanf(fpInFile, "%d%d%f%f%d", &lLong1, &lLong2, &fFloat1,
&fFloat2, &lNum);
if (iRead==0 || iRead==EOF) break;
} while (lX < lLastX || lY < lLastY);

}

I am wondering if I should just do binary reading so as to have more
control over what is going on.

Many thanks in advance for any assistance,
Peter.


Dear Peter,

Your are not closing the file.
Use fclose for closing the file.

Thanks and regards,
Amal P.- Hide quoted text -

- Show quoted text -

Sorry. I am closing the file with
fclose(fpInFile);
but forgot to include that in the sample code that I posted. The
problem, unfotruntately, lies elsewhere.

Thanks,
Peter.



"PeterOut" <Ma**********@excite.comwrote in message
news:11**********************@c77g2000hse.googlegr oups.com...

>I am using MS Visual C++ 6.0 on Windows XP 5.1 (SP2).

I am not sure if this is a C, C++ or MS issue but fscanf has been
randomly hanging on me. I make the call hundreds, if not thousands,
of times but it hangs in different places with the same data. The
offending code follows.

ReadFile(char *csFileName)
{
float fFloat1, fFloat2;
long lLong1, lLong2, lNum, lLastX = iColumns-1, lLastY =iRows-1;
int iRead;
FILE *fpInFile;

if ((fpInFile= fopen(csFileName, "r")) == NULL) return
ErrorOpeningFile(csFileName);

do
{
// It randomly hangs on the followinf
line
iRead=fscanf(fpInFile, "%d%d%f%f%d", &lLong1, &lLong2, &fFloat1,
&fFloat2, &lNum);

%d is for type ''int''. For type ''long'', use %ld.

Also make sure you''ve #included <stdio.hfor the
declaration of ''fscanf()''.

-Mike


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

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