Solved

Moving within a File

Posted on 2000-03-25
3
183 Views
Last Modified: 2013-11-20
If you have a linear file
as in the following

bof
john martin
bill jones
mark smith
eof
how do you move to a particular line.
e.g in the example above how would i
move to just before the name jones.
i've tried CFile::Seek() but that just
moves to the offset position in bytes
any ideas?

0
Comment
Question by:Yozzer
3 Comments
 
LVL 2

Expert Comment

by:wyy_cq
ID: 2656486
method 1:

move_to_header
for(i=0;i<you_want;read_line())
{
}

method 2:
build a index file to record the position of every line


0
 
LVL 3

Expert Comment

by:ghimireniraj
ID: 2656861
What do you want to do move to the fist char of every next line..

just  keep reading every character in the file from the begining and skip it till you get a "\n"

like


int length;
length=file1.GetLength();
//get length of file in length;
char abc;
while(length)
{
do
{
file1.Read(abc,1);
length--;
}
while(abc=="\n");
///
/*  this is the place where you get to the begining of all new lines */

}


well if this is what you want...
0
 
LVL 1

Accepted Solution

by:
YiannisVolos earned 50 total points
ID: 2658038
Hi.

You seem to use MFC. If you would be interested in using functions that I created to manipulate data in sequential/linear files you could have a look at my source code and then you could award me :)

I adapted my examples for Visual C++ (Windows) and Turbo C++ for Dos.

If you have any questions concering how the code works please inform me and I'll gladly provide you more help.

The two examples are located at:
http://volosm.arsdigita.org/devzone/dnlds/c_source.zip
(from the c_source.zip the seek.cpp reads sequential files, append.cpp writes sequential files)

and
http://volosm.arsdigita.org/devzone/dnlds/multi.zip
(this is a full VC++ example)

If you have time maybe you could have a look at my website:
http://volosm.arsdigita.org


Thanks.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to calculate times for developing software? 8 67
format the code in java 6 93
fizzArray2 challenge 1 78
"Black Box" Testing of Control System Software 2 49
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question