1
I have a question about storing information in array, I thought, when inside a loop, an array of size 200, for example char nome[200]
it would be populated continuously until there is no more space left to store the information, causing the system to return an error, but in some examples I have done, the array is reused in the loop and instead of being "completed" in the space it still has, it seems that the space that was used has the information replaced, if it really happens, why the array is not completed?
int main()
{
int n,i;
char ch;
int length;
scanf("%d", &n);
char abc[200];
for( i = 0; i < n; i++)
{
while( (ch = getchar() != '\n') && ch != EOF);
fgets( abc,200,stdin);
length = strlen( abc);
printf("%d", length);
printf("%s", abc);
}
}
This is an example. if I type one sentence of size 100 and then another of size 100 the second will take the place of the first, instead of completing the other 100 that was left? and if I type one of size 200 and then another of size 100, the replacement will occur?
Excellent! thanks for the explanation.
– Vitor Matos