cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/25/02:37:40

From: "Ryan" <ryang AT chariot DOT net DOT au>
Newsgroups: comp.os.msdos.djgpp
Subject: best way to read selected data from a file?
Date: Sun, 24 Oct 1999 14:39:39 +0930
Lines: 59
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
NNTP-Posting-Host: 210.9.21.114
X-Original-NNTP-Posting-Host: 210.9.21.114
Message-ID: <3812949e_2@news.chariot.net.au>
X-Trace: 24 Oct 1999 14:39:50 +0950, 210.9.21.114
X-Original-NNTP-Posting-Host: 203.30.236.75
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi....

Im relatively new to C.

I want to find a way to read a certain line from a text file plus also
perhaps read a certain line from a text file which contains certain words.

I have no problem opening files and reading the first line or the next line
after that.

Ie.  if I use two fscanf's  after each other that would read the first and
second word.

Or I could use fgets and say what max characters I could use.



But what If I want to go straight to line 15 and read that line?


Has it something to do with fseek etc?

because from the notes I am reading I tried to implement Fseeks and
fsetpos's without any luck.

I could get it to read different sections of the file, yes, but i couldnt
get it to read the exact lines I wanted.


I also tried using ftell to try to comprehend how the cursor location is
derived.

But it seemed to follow some weird pattern, not simple like line 1 is 1 or
anything.

Line 3 would return an int of 15 then line 4 would return 18.....and i gave
up on that.


WHY is it SOOO hard to do this seemingly simple function???  Why when I read
every tuturial on file handling it only explains how to read and write to a
file in the most basic of circumstances.

This is only good for writing one word to the top of the file or reading
from the top.....but there has to be a way I am sure.....but why do no books
tell me how to do it???

COuld someone please explain the ins and outs of file handling so that I
will be able to read any bit of data I want at any position i want, plus
also doing this with arguments so I can search through text files and read
the lines I need???

I find all other parts of C pretty straight forward and in s tep by step
fashion.....but I am in a big void here when it comes to advanced file
handling...




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019