Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Direct File manipulation

Posted on 2002-04-05
5
Medium Priority
?
179 Views
Last Modified: 2010-04-02
Hello,
   I need to search directly for different records within a file in its actual location...as basically as possible.  Does anyone have any suggestions for me?
Thanks
0
Comment
Question by:pingle
[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
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6921176
See http://support.microsoft.com/support/kb/articles/Q292/4/85.ASP ('HOWTO: Programmatically Save an HTML Page to Disk'). The scoop is:

Accomplishing this task from a Visual C++ host is very straightforward. You can use an IWebBrowser2
interface to call the QueryInterface method for the IHTMLDocument2 interface. After you obtain a pointer
to the document, then call QueryInterface for the IPersistFile interface. After you obtain this interface
pointer, you can call the save method to save the file to disk.

   HRESULT          hr    = E_FAIL;
   IDispatch*       pDisp = NULL;
   IHTMLDocument2*  pDoc  = NULL;
   
   pDisp                  = m_webOC.GetDocument();

  if(SUCCEEDED(hr = pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc)))
  {
      IPersistFile*     pFile     =     NULL;
      if(SUCCEEDED(pDoc->QueryInterface(IID_IPersistFile,(void**)&pFile)))
      {
    LPCOLESTR     file = L"c:\\test1.htm";
    pFile->Save(file,TRUE);
      }
  }
0
 
LVL 86

Expert Comment

by:jkr
ID: 6921178
Ooops, sorry, wrong browser window :o)
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 6921188
Well, the easiest way for navigating a file is using 'fseek()':


#include <stdio.h>

void main( void )
{
   FILE *stream;
   char line[81];
   int  result;

   stream = fopen( "fseek.out", "w+" );
   if( stream == NULL )
      printf( "The file fseek.out was not opened\n" );
   else
   {
      fprintf( stream, "The fseek begins here: "
                       "This is the file 'fseek.out'.\n" );
      result = fseek( stream, 23L, SEEK_SET);
      if( result )
         perror( "Fseek failed" );
      else
      {
         printf( "File pointer is set to middle of first line.\n" );
         fgets( line, 80, stream );
         printf( "%s", line );

      }
      fclose( stream );
   }
}

0
 
LVL 30

Expert Comment

by:Axter
ID: 6921320
If you're running on a Windows platform, you can do a MapView, and get a (void*) pointer to the data in the file.
You can then use regular C++ functions to manipulation the data in the file.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6921337
FYI:
You can also do MapView from unix using mmap and munmap functions.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

704 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