Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Fseek() and fgets()
Message
De
08/08/1998 09:29:49
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00124862
Message ID:
00125021
Vues:
22
>Hello All,
>I have an app that needs to fopen an ascii file,
>fgets() pulls out the first string.
>I manipulate the data here and then;
>I need to overwrite the line with the new info.
>All this inside a DO while Not feof() loop;
>
>I am not using fputs() to write the line becuase various
>sources of these ascii files may have different carriage returns so I have determined before hand what the return is and store it in a variable. THis way I can =fwrite(maniupateed data + variable)
>
>My problem is I am not successfully moving down with the file
>pointer thus never gettting to FEOF().
>
>I know the length of each record and I also have a counter as I go down the file. SO, I could do an fseek() to the top of the fiel and then move down by string length * the counter.
>
>How do I do this?
>Thanks,
>Sandy

Always remember where your file pointer was before you read the last line. So:

lnLastPos=Fseek(gfh, 0,1) zero bytes offset, from current position
yourString=Fgets(gfh)

[ crunch & munch the data ]

=fseek(gfh, lnLastPos,0) go back to where you were (exact position offset, from start of file)
=fwrite(gfh, YourNewString)

Your new string should be padded with some blanks to the length of the string you got first, and surely not longer than it.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform