?
Solved

Moving within a File

Posted on 2000-03-25
3
Medium Priority
?
188 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 150 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 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