Solved

Moving within a File

Posted on 2000-03-25
3
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change owner from userA to server Local Administrators 7 71
Use of condition with 'serial' in ansible 2 88
unix example issues 18 106
Authenticate using sesu from script 7 117
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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