int main()
{
float T[100];
float *pt=T;
float suma = 0, srednia, zmienna;
int rozmiar;
printf("How many numbers would you like to put in: ");
scanf(" %d", &rozmiar);
int dzielnik = rozmiar;
printf("\n Enter the number: \n");
for(int i = 0;i<rozmiar;i++)
{
printf("\n i = %d", i );
scanf("%99f\n", &zmienna);
*(pt+i) = zmienna;
}
return 0;
}
This is my code. The idea is simple. I have an array; I want to scan how many numbers I want to put into the array and then put numbers into array. I don't know why but scanf
ignores the second variable that I put in array.
If I put "2" in first scanf, program wants 3 variables from me.
My output should be like this:
How many numbers would you like to put in: 2
Enter the number:
i = 0
2 (my number)
i=1
3 (my number)
but it's actually like this:
How many numbers would you like to put in: 2
Enter the number:
i = 0
1 (my number)
2 (my number)
i = 1
3 (my number)