Loading read_file.c +25 −22 Original line number Diff line number Diff line Loading @@ -4,14 +4,17 @@ double* Array_costheta; double* Array_pdeg; double* Array_Intensity; int tot_elements; int columns; char riga[1000]; void read_file(void) { int ii; double value1, value2, value3; FILE* file; file = fopen(simulfile, "r"); if (file == NULL) { printf("Error opening file '%s'. Please check the file name and location.\n", simulfile); Loading @@ -22,11 +25,13 @@ void read_file(void) Array_pdeg = (double*)malloc(sizeof(double)); Array_Intensity = (double*)malloc(sizeof(double)); int c; double value1, value2, value3; ii = 0; while (fscanf(file, "%lg %lg %lg ", &value1, &value2, &value3) == 3) while (fgets(riga, sizeof(riga), file) != NULL) { columns = sscanf(riga, "%lg %lg %lg", &value1, &value2, &value3); if (columns == 3) { // printf("ii=%d: %lf %lf %lf\n", ii, value1, value2, value3); Loading @@ -39,19 +44,17 @@ void read_file(void) Array_Intensity = realloc(Array_Intensity, (ii + 2) * sizeof(double)); ii++; // Ignora il resto della riga while ((c = fgetc(file)) != '\n' && c != EOF); } } tot_elements = ii; /*for (ii = 0; ii < tot_elements; ii++) /* for (ii = 0; ii < tot_elements; ii++) { printf("%5.4f %5.4e %lf \n", Array_costheta[ii], Array_pdeg[ii], Array_Intensity[ii]); } */ // Reimposta la posizione del cursore all'inizio del file // fseek(file, 0, SEEK_SET); // Close the file fclose(file); Loading Loading
read_file.c +25 −22 Original line number Diff line number Diff line Loading @@ -4,14 +4,17 @@ double* Array_costheta; double* Array_pdeg; double* Array_Intensity; int tot_elements; int columns; char riga[1000]; void read_file(void) { int ii; double value1, value2, value3; FILE* file; file = fopen(simulfile, "r"); if (file == NULL) { printf("Error opening file '%s'. Please check the file name and location.\n", simulfile); Loading @@ -22,11 +25,13 @@ void read_file(void) Array_pdeg = (double*)malloc(sizeof(double)); Array_Intensity = (double*)malloc(sizeof(double)); int c; double value1, value2, value3; ii = 0; while (fscanf(file, "%lg %lg %lg ", &value1, &value2, &value3) == 3) while (fgets(riga, sizeof(riga), file) != NULL) { columns = sscanf(riga, "%lg %lg %lg", &value1, &value2, &value3); if (columns == 3) { // printf("ii=%d: %lf %lf %lf\n", ii, value1, value2, value3); Loading @@ -39,19 +44,17 @@ void read_file(void) Array_Intensity = realloc(Array_Intensity, (ii + 2) * sizeof(double)); ii++; // Ignora il resto della riga while ((c = fgetc(file)) != '\n' && c != EOF); } } tot_elements = ii; /*for (ii = 0; ii < tot_elements; ii++) /* for (ii = 0; ii < tot_elements; ii++) { printf("%5.4f %5.4e %lf \n", Array_costheta[ii], Array_pdeg[ii], Array_Intensity[ii]); } */ // Reimposta la posizione del cursore all'inizio del file // fseek(file, 0, SEEK_SET); // Close the file fclose(file); Loading