![](/img/trans.png)
[英]Changing a for loop to a while loop doesn't work correctly (simple code)
[英]Loop doesn't work correctly (strings)
我正在编写一个程序,它将按字母顺序对输入的单词进行排序,但是我发现无法继续进行,因为循环无法按预期工作。
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main()
{
char string[50][50];
int i, n;
printf("Insert the number of strings: ");
scanf("%d ", &n);
for(i=0; i < n; i++)
{
printf("Insert %d. string: ", i+1);
fgets(string[i],50,stdin);
}
return 0;
}
我尝试使用gets()并尝试使用fgets(),但是结果是相同的。 它打印:
Insert 1. string: Insert 2. string:
然后,您可以插入字符串,但比指定的字符串少1。
for循环后有分号!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.