陷入无限循环 [英] Running into an infinite loop
本文介绍了陷入无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的程序正在陷入无限循环.您能告诉我代码有什么问题吗?
Hi,
My program is running into an infinite loop. Can you please tell me what is wrong with the code?
char ch=0;
FILE *p = NULL, *q = NULL;
p = fopen(argv[1], "r+");
q = fopen(tempfilename, "w+");
while ((ch = getc(p)) != EOF)
{
// Normal if else statements
}
我也试着给..但徒劳.. :(
I also tried giving.. but in vain.. :(
int ch;
预先感谢,
Thanks in advance,
推荐答案
代码没有错误.唯一的错误是我可以看到您不验证fopen是否可以打开文件.验证p!= NULL.如果p为null我需要问您使用的是什么编译器?可能是旧的
code has no mistake. only mistake i can see you are not verifying whether fopen can open the file or not. verify if p!=NULL. if p is null I need to ask what compiler are you using? probably old
while ( 1 )
{
ch = fgetc ( fs ) ;
if ( ch == EOF )
break ;
else
fputc ( ch, ft ) ;
}
请参考 http://www.go4expert.com/forums/showthread.php?t=2977 [ ^ ]
祝您编码愉快!
:)
refer http://www.go4expert.com/forums/showthread.php?t=2977[^]
Happy Coding!
:)
这篇关于陷入无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文