#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;
}
Wenn n = 3
dann dauert es nur zwei Strings bei Index 1
und 2
es überspringt 0
, warum es dauert nicht Eingang in 0
?gets() Funktion in C-Eingang in einem Array
Hier ist a
mein Array von Strings.
'gets' ist eine Funktion, die nicht korrekt verwendet werden kann. Als solche wurde es aus dem neuesten C-Standard entfernt. Es ist ein Fehler. Bitte beachten Sie stattdessen 'fgets'. – user694733
Weil das 'scanf', bevor es ein' \ n' im Eingabepuffer belässt und 'gets' liest es in der ersten Iteration. BTW, [** Nimm niemals 'gets' **. Es ist gefährlich!] (Http://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used) –