主题:C语言代码运行不同,求大侠啊
char TI_file[1000];
double SUMAC=0,double TL=0,double basin_area=0;
double *fractions,*AC,*TI;
int k, n,n_bins;
const char format[] = "%s %f\n";
char line[200];
FILE *fp;
strcpy(TI_file,directory);
strcat(TI_file, "TI_file.txt");
printf("Reading TI histogram from TI_file.txt...\n");
printf(TI_file);
//--------------------------
// Open the TI input file
//--------------------------
fp = fopen(TI_file, "r");
if (fp == NULL) {
printf("ERROR: Couldn't open TI input file.\n");
exit(-1);
}
//--------------------------
// Read the number of bins
//--------------------------
fscanf(fp, "%u", &n_bins);
printf("%s %u\n", "Number of bins = ", n_bins);
TI = (double *)malloc(n_bins * sizeof(double));
AC = (double *)malloc(n_bins * sizeof(double));
fractions = (double *)malloc(n_bins * sizeof(double)); //*********
//---------------------------
// Read TI and area values
//---------------------------
for (n=0L; n < n_bins; n++) {
fscanf(fp, "%lf %lf", AC[n], TI[n]);
printf("%f %f\n", AC[n], TI[n]);
basin_area = basin_area + AC[n]; /* should add to 1.0 */
}
//------------------------
// Close the input file
//------------------------
fclose(fp);
printf(format, "Basin area sum = ", basin_area);
//-----------------------------
// Compute the area integral
//-----------------------------
TL = 0.0;
fractions[0] = AC[0] / basin_area;
SUMAC = fractions[0];
for (k=1; k < n_bins; k++) {
fractions[k] = AC[k] / basin_area;
SUMAC = SUMAC + fractions[k];
TL = TL + AC[k]*(TI[k] + TI[k-1])/2.0;
}
printf("Finished reading file.\n\n");
怎么老是跑步通啊
double SUMAC=0,double TL=0,double basin_area=0;
double *fractions,*AC,*TI;
int k, n,n_bins;
const char format[] = "%s %f\n";
char line[200];
FILE *fp;
strcpy(TI_file,directory);
strcat(TI_file, "TI_file.txt");
printf("Reading TI histogram from TI_file.txt...\n");
printf(TI_file);
//--------------------------
// Open the TI input file
//--------------------------
fp = fopen(TI_file, "r");
if (fp == NULL) {
printf("ERROR: Couldn't open TI input file.\n");
exit(-1);
}
//--------------------------
// Read the number of bins
//--------------------------
fscanf(fp, "%u", &n_bins);
printf("%s %u\n", "Number of bins = ", n_bins);
TI = (double *)malloc(n_bins * sizeof(double));
AC = (double *)malloc(n_bins * sizeof(double));
fractions = (double *)malloc(n_bins * sizeof(double)); //*********
//---------------------------
// Read TI and area values
//---------------------------
for (n=0L; n < n_bins; n++) {
fscanf(fp, "%lf %lf", AC[n], TI[n]);
printf("%f %f\n", AC[n], TI[n]);
basin_area = basin_area + AC[n]; /* should add to 1.0 */
}
//------------------------
// Close the input file
//------------------------
fclose(fp);
printf(format, "Basin area sum = ", basin_area);
//-----------------------------
// Compute the area integral
//-----------------------------
TL = 0.0;
fractions[0] = AC[0] / basin_area;
SUMAC = fractions[0];
for (k=1; k < n_bins; k++) {
fractions[k] = AC[k] / basin_area;
SUMAC = SUMAC + fractions[k];
TL = TL + AC[k]*(TI[k] + TI[k-1])/2.0;
}
printf("Finished reading file.\n\n");
怎么老是跑步通啊