跳过用C scanf函数声明 [英] Skipping over Scanf statement in C
问题描述
我写的刽子手客观的C程序。我需要复制已经给我另一个程序。我已经做了大部分,但我有一个问题。它具有精确复制其他程序,所以我走进了另一个和输入的字符到字长。它想出了数必须介于3至14(含)语句,并要求我再输入一个数字,但它开始无限循环。它的工作原理,当我进入低于3一个数字,大于14(出现的错误,并请求另一个输入),但以字母它无限循环。有任何想法吗???
谢谢
同时(我== 0){ 的printf(\\ n \\ n>请输入字长:);
scanf函数(%i的,&安培;字长);
的printf(\\ n \\ n);
如果(数→3&放大器;&放大器;数&下; 14){
继续;
}
其他的printf(数必须是3至14(含)之间的);
}
您正在检查数量
,但似乎你必须检查字长$ C $的c>变量,(如@Narkha指出的)使用
破
而不是继续
从循环退出
I am writing an objective c program for hangman. I need to replicate another program which has been given to me. I have done most of it, but am having an issue. It has to replicate the other program exactly, so I went into the other one and entered a character into the wordlength. It came up with the "number must be between 3 and 14 (inclusive)" statement, and asked me to enter a number again, but it started to loop infinitely. It works when i enter a number lower than 3 and larger than 14 (comes up with the error and asks for another input) but with a letter it infinitely loops. Any ideas??? Thanks
while (i == 0){
printf("\n\n > Please enter a word length: ");
scanf("%i", &wordLength);
printf("\n\n");
if (number > 3 && number < 14) {
continue;
}
else printf("number must be between 3 and 14 (inclusive)");
}
You are checking number
but seems that you must check wordLength
variable, and (as pointed out by @Narkha) use break
instead of continue
to exit from loop.
这篇关于跳过用C scanf函数声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!