/* Your Name Brenton */
/* Lab 4 */
/* Figure the area of the top of a cylinder */
/* and the volume of a cylinder */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//#define FILE_IN "lab4.dat"
#define FILE_IN "lab4sample.dat"
int main(void)
{
printf("Brenton Kludt, Lab 4");
int count = 1;
double radius, height, area, vol;
FILE * input_file;
FILE * output_file;
input_file = fopen ("lab4sample.dat", "r");
if(input_file == NULL){
printf("Error on opening the input file \n");
exit (EXIT_FAILURE);
}
output_file = fopen ("lab4.out", "w");
if(output_file == NULL){
printf("Error on opening the output file");
exit (EXIT_FAILURE);
}
fprintf(output_file, "\nBrenton Kludt. Lab 4.");
while ((fscanf(input_file, "%lf%lf%lf", &radius, &height)) == 2)
{
vol = radius * height;
area = M_PI * radius * radius;
fprintf(output_file, "\nCylinder %1d", count);
fprintf(output_file, "\nThe radius is: %9.3f", radius);
fprintf(output_file, "\nThe height is: %9.3f", height);
fprintf(output_file, "\nThe top area is: %9.3f", area);
fprintf(output_file, "\nThe volume is: %9.3f\n", vol);
count++;
}
fclose(input_file);
fclose(output_file);
return EXIT_SUCCESS;
}
Все компилируется правильно. Код используется для доступа к файлу с набором данных, для которого он был обработан, и для создания отформатированного выходного файла. Я использовал g cc -lm thisfile. c, для которого создается a.out, и когда я запускаю a.out, он зависает и через 10 секунд выдает ошибку сегментации. Проблема в коде или проблема с разрешениями?