I seem to stuck in a extremely simple question, but I cannot fix it and understand why. Below is my code:
#include <stdio.h>
#define SIZE 8
int main(void){
int i, j;
double nums[SIZE];
double input;
printf("Enter 8 doubles: ");
for (i = 0; i < SIZE; i++){
nums[i] = scanf("%lf", &input);
}
for (i = 0; i < SIZE; i++){
printf("%lf ", nums[i]);
}
return 0;
}
Below is the result I got:
Enter 8 doubles: 1 2 3 4 5 6 7 8
1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
What is the main problem about my code? Thank you!
scanfreturns the number of items scanned. You want to assigninputto your array items.