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;
}
의 C 입력() 함수를 가져, 왜 0
에 입력하지 않는다?는 그것이 <code>0</code> 건너 뛰고 인덱스 <code>1</code>에서 두 개의 스트링을 취하고 <code>2</code> 다음 <code>n = 3</code> 경우 배열
여기서 a
은 문자열 배열입니다.
'gets'는 올바르게 사용할 수없는 기능입니다. 따라서 최신 C 표준에서 제거되었습니다. 그것을 사용하는 것은 버그입니다. 대신'fgets'을 사용해보십시오. – user694733
그 전에'scanf'는 입력 버퍼에'\ n'을 남겨두고 첫 번째 반복에서'gets'를 읽습니다. BTW, [** 결코'gets' **를 사용하지 마십시오. 그것은 위험합니다!] (http://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used) –