Thread: FILE I/O
View Single Post
  #1 (permalink)  
Old August 12th, 2003, 07:11 AM
awhittaker awhittaker is offline
Authorized User
 
Join Date: Aug 2003
Location: Cary, NC, USA.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default FILE I/O

Hi,

I have a text file that I am trying to update. I want to open the file, change a couple of fields and write the rest of the file back as the same. I have tried to use:

FILE *fp;
if (fp = fopen(sFile, "r+") != NULL)
{...}

but I do not understand how you can open the file, write the data until you know you are where you want to change the data, change that text, then continue to write the rest of the file. I have a text file like so:


FILE I:\30050N50.P01 RP090L v3.32 - 04 DEC 2001 ENGLISH UNITS

COUNTY 50 ROUTE nc 50 DIR North(+) LANE 1
OPERATOR jimmy DRIVER jimmy VEHICLE 1151 EQUIPMENT 062-1151
FILE_NAME 30050n50 USER_REF_2 0 USER_REF_3 30050n50
DATE 05/02/2003 TIME 12:22:20 DCF 14944 E
WAVELENGTH_LONG 300 ft
WAVELENGTH_SHORT none

        MILES IN IN/MI
                     ROUGH RUT RUT AVG
  FROM TO DIST AVG STD IRI 1 IRI 2 IRI
--------- --------- ------- ----- ----- ------ ------ ------
    0.000 0.100 0.100 0.07 0.055 96 82 89
    0.100 0.200 0.100 0.01 0.081 85 81 83
    0.200 0.300 0.100 0.06 0.046 73 71 72
    0.300 0.400 0.100 0.01 0.045 78 89 84
    0.400 0.500 0.100 -0.00 0.048 70 78 74
    0.500 0.600 0.100 0.00 0.038 79 82 81
    0.600 0.700 0.100 -0.04 0.042 71 68 69



Suppose I want to change ROUTE from "nc 50" to "NC 181". How would I do that and keep the rest of the file the same?

Thanks!
Andy

Reply With Quote