Message-Id: <4.3.2.7.0.20011128100546.00ab2940@soils.umn.edu> X-Sender: mdusaire AT soils DOT umn DOT edu X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Wed, 28 Nov 2001 10:06:16 -0600 To: djgpp AT delorie DOT com From: Martin duSaire Subject: limited space? Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Reply-To: djgpp AT delorie DOT com Hi, I am running a small program to copy selected columns from a data file. The program runs fine, except that it appears to exit (without error) after reading only about half of the 200+ data groups. The main loop is controlled with: while (fscanf(fpin, "%f, s)!=EOF) I had a similar problem with a routine that created subdirectories from a list of names. Any ideas? The code is shown below. Thanks. Martin #include #include #include int main() { FILE *fpin, *fpout; float rho = 0.0, target = 0.0, tint = 0.0, x, y[8], z[8]; unsigned b = 1, dummy, first = 1, i, l, m, ndepth = 0, t = 0; char s[40], fname[40]; cout << " This program uses linear interpolation to estimate depth to a target resistivity value based on output from Res2Dinv. User must provide input filename, output filename, # of depth levels of data, and target resistivity value in Ohm-m. \n\n"; cout << " Name of resistivity data file: [40 no spaces] "; cin >> fname; fpin = fopen(fname, "r"); l = strlen(fname)-4; strncpy(s,fname,l); fname[l] = '\0'; fpout = fopen(fname, "w"); cout << " Number of depth levels read from output file " << fname << "\n"; cout << " Target resistivity (Ohm-m): "; cin >> target; while ((fscanf(fpin, "%f", &x))!=EOF){ if (first){ y[0] = x; ndepth = (unsigned) x; fprintf(fpout, "%u\n", (unsigned) y[0]); for (i = 1; i <= ndepth; i++){ fscanf(fpin,"%f", &y[i]); fprintf(fpout, "%6.2f ", y[i]); } fprintf(fpout, "\n"); fprintf(fpout, "%6.2f\n",target); } else{ z[0] = x; for (i = 1; i <= ndepth; i++) fscanf(fpin,"%f", &z[i]); /* z[0] contains the position along */ /* the transect "x" */ } t = ndepth; b = 1; if ((target < z[t]) && (target > z[b])){ while ((t-b) > 1){ m = (t+b)/2; if (z[m] > target) t = m; else b = m; } tint = (target-z[t])*(y[t]-y[b])/(z[t]-z[b])+y[t]; } else tint = 0.0; if (!first){ /* for (i = 0; i <= ndepth; i++) fprintf(fpout, "%6.2f ", z[i]); */ fprintf(fpout, "%6.2f ", z[0]); fprintf(fpout, "%6.2f\n", -tint); } else first = 0; } fclose(fpin); fclose(fpout); } /* end of main */ ------------------------------------- 439 Borlaug Hall 1991 Upper Buford Circle St. Paul, MN 55108 Office #176 Phone (612)625-3716 Fax (612)625-2208 -------------------------------------