Hi everyone, i got a question about the fscanf.
I input a file and scan the data in the file.
It works good that if there are integers in line1,2,3,4 in the file.
However, it does not work good with empty file or the file only has dat in line 1 and line 2.
Please help me. Thanks
printf("\nThe results from file %s are : \n", filename);
printf("____________________________________________________________________\n");
printf("| # of data | sum | range | mean | variance | standard deviation|\n");
printf("____________________________________________________________________\n");
fscanf(inputFile, "%d", &number_of_data);
for(i =0; i <number_of_data; i++)
{
fscanf(inputFile, "%d", &all_number);
sum += all_number;
}
printf("| %d| %d| \n", number_of_data, sum);
printf("____________________________________________________________________\n");
fscanf(inputFile, "%d", &number_of_data_1);
for(i =0; i <number_of_data_1; i++)
{
fscanf(inputFile, "%d", &all_number_1);
sum_1 += all_number_1;
}
printf("| %d| %d| \n", number_of_data + number_of_data_1, sum_1+sum);