Re: Reading a file from a specified range

From: mkarja (mmmc_reptail_at_hotmail.com)
Date: 10/27/04


Date: 27 Oct 2004 06:08:03 -0700


> "Chris \( Val \)" <chrisval@bigpond.com.au> wrote in message >
> news:<2u6eofF26st2gU1@uni-berlin.de>...
>
> You know, programmers are supposed to actually program :-)
>

Heh, yeah so I've heard. I don't know where that idea is from :)
Actually I did some programming on my own (gasp) and I managed
to solve my problem. I was perhaps a bit hasty on asking for
help, but I was in a hurry to get it done. Deadline tomorrow.

Here's how I did it if anyones interested. Not sure if it's the
best way to do this, but this is how I did it anyways.

============ code start =========================
std::ifstream infile( "logfile.txt" );

std::string commandResponse;
std::vector<std::string> commandResponse2;
std::string Buffer;
int i;
int j;

while( std::getline( infile, Buffer ) )
{
        commandResponse2.push_back(Buffer);
        if( Buffer.find( "/***" ) )
                continue;

        infile.seekg( 1, std::ios_base::cur );
        std::getline( infile, Buffer );
        break;
}

int respSize = commandResponse2.size();

for(i=respSize-1; i>0; i--) {
        if ( commandResponse2.at(i).find( "<" ) != std::string::npos )
        {
                for(j=i; j<respSize; j++) {
                        commandResponse += commandResponse2.at(j);
                }
                break;
        }
}

commandResponse += Buffer;

Buffer = "";

printf("\n Result2: \n %s \n", commandResponse.c_str());

infile.close();
============ code end =========================
============ logfile start =========================
< [command name]

LOADING PROGRAM

/*** SYNTAX ERROR ***/
/*** INVALID DELIMITER ***/
============ logfile end =========================

There's a snippet of the code and the part of the logfile that
matters. There's bunch of lines and text before and after what's
on this example snippet from the logfile.
The code above goes thru the logfile and searhes until it finds
the /*** bit and puts it in the vector. Then it gets the next
line and puts it in the Buffer.
Then it goes through the vector backwards from the last row in
the vector until it finds the < character and appends it all to
the string. Last it appends the contents of the Buffer string
to the string as well. Or something like that at least.

Thanks for you help and patience Chris. I propably wouldn't have
been able to do this on time without your help. So BIG thanks.

----
mkarja


Relevant Pages

  • RE: safe strcpy()?
    ... Programming and be paranoid about everything...unless you meant ... For each character in a printable string, I check whether it needs to be ... I stop copying and send the buffer ...
    (SecProg)
  • Re: Why GCC does warn me when I using gets() function for accessing file
    ... Seriously -- programming may be too ... It requires a certain amount of programming experience ... buffer of size 100 might seem perfectly reasonable. ... concept of stack smashing. ...
    (comp.lang.c)
  • Re: Discovering variable types...
    ... >- but I suppose MS expect us to use wrappers ... memory allocations for your variables from disk as well. ... >They most certainly are of fixed size, changing the size of a String ... >>me to keep buffer size and current postion right in the memory block. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Secure C library
    ... I read much of the new "security TR", and gee, I don't know. ... the buffer from the buffer size. ... It is not hard to design a better form of buffer and string handling. ... but this is just one example of how thoughtful interface design can ...
    (comp.std.c)
  • Re: Secure C library
    ... >> string functions don't make much sense once you add bounds-checking ... >> designing an interface just for the purpose of reducing the frequency ... > make buffer size decisions more visible, ... Bstrlib is also very interoperable with char *'s, ...
    (comp.std.c)