0
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main()
{
int n,i;
char a[10][100];
printf("\n Enter the no. of strings:");
scanf("%d",&n);
printf("\n enter the %d numbers:",n);
for(i=0;i<n;i++)
{
printf("\n %d",i);
gets(a[i]);
}
for(i=0;i<=n;i++)
{
puts(a[i]);
}
return 0;
}
如果n = 3
那么在指数1
只需要两个字符串和2
它跳过0
,为什么没有采取输入在0
?获取C输入()函数在数组
这里a
是我的字符串数组。
'gets'是一个不可能正确使用的函数。因此,它已从最新的C标准中删除。使用它是一个错误。请考虑使用'fgets'来代替。 – user694733
因为它之前的'scanf'离开了输入缓冲区中的'\ n',并且'gets'在第一次迭代中读取它。顺便说一句,[**不要使用'gets' **。这是危险的!](http://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used) –