I'm trying to sum all the numbers from a file by storing numbers in an array then sum the array elements. However, the compiler says
during RTL pass: ira
/home/ubuntu/CLionProjects/printnum/main.c: In function ‘main’:
/home/ubuntu/CLionProjects/printnum/main.c:32:1: internal compiler error: Bus error
}
^
cc: internal compiler error: Bus error signal terminated program cc1
What is wrong?
int main(int argc, char *argv[])
{
FILE *fp;
double tmp;
double num[10],sum;
int count = 0,i;
fp = fopen("numbers.txt", "r");
if (fp != NULL)
{
while (fscanf(fp, "%lf", &tmp) != EOF)
{
num[count++] = tmp;
}
}
else {
printf("xxxxxxx");
}
for ( i = 0 ; i <= sizeof(num);i++) {
sum += num[i];
printf("%lf", sum);
}
fclose(fp);
}