I have this piece of code:
#include <stdio.h>
int average(int array []);
int main () {
int num_array[];
int x = 0;
while(num_array[x] != -1){
printf("Enter a number\n");
scanf("%d",&num_array[x]);
x++;
}
printf("%d\n", average(num_array));
return 0;
}
int average(int array[]){
int i;
int total_size = (int)sizeof(array);
int sum = 0;
for(i = 0; i < total_size; i++){
sum = sum + array[i];
}
return sum/total_size;
}
But i get an error at compile time, because i'm not initialising the array. However i can't do it, since i don't know it's size.
How can i solve this ?