[英]How to make printf run only once in loop
How to let printf run only once in loop, the P is argv so it will print Guess 4 times if the value of P is 4如何让 printf 在循环中只运行一次,P 是 argv 所以如果 P 的值为 4,它将打印 Guess 4 次
while (h!=P) {
for (int i=0;i<P;i++)
{
n[i]=1,j[i]=1;
printf("\nGuess:");
scanf("%d",&guess[i]);
}
Output example Output 示例
1 3 4 1
Guess:1 3 4 1
Guess:
Guess:
Guess:
4H0X
correct
1 4 1 2
Guess:4 1 2 1
Guess:
Guess:
Guess:
0H4X
Guess:
If you wnat only one "Guess" per for loop:如果每个 for 循环只有一个“猜测”:
for (int i=0;i<P;i++) {
...
if (i == 0)
printf("\nGuess:");
...
}
while (h!=P) {
printf("\nGuess:");
for (int i=0;i<P;i++)
{
n[i]=1,j[i]=1;
scanf("%d",&guess[i]);
}
I think just by putting that printf out from the FOR you can make it我认为只需将 printf 从 FOR 中取出即可
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.