BL>
BL> There's an old expression attributed to BP about expecting and
BL> getting the best out the scouts. "When in doubt, hand the kid the
BL> end with the jam on it."
Who is BP and what the hell does that expression mean?
BL> I think I have the mechanics of reading in the file worked out and
BL> then writing it back to the same file (although I wouldn't mind
BL> learning from a few code snippets how others have dealt with this
BL> problem); however, I'm not sure how to handle the line by line
BL> checking before writing it back to the file. Any help and ideas
BL> would be greatly appreciated.
Well, I think you will get numerous responses, but here is one...
This assumes that we are invoking the program by redirecting
the input and the output from the command line, i.e. we will
run this as :
progname outfilename
This gives us the advantage of being able to test this program
with the console without having to create test files if we want.
BTW do you understand redirection, etc?
Also since you didn't say what the unwanted text is, we have to
black box that one, lets assume a boolean function :
bool wantLine ( const char * cszLine ) ;
=============================================================
# include
// If you have an ANSI compiler and do not need to define bool,
// omit the next line
enum bool { false = 0 , true } ;
# define MAX_LINE 2047
bool wantLine ( const char * cszLine ) ;
// For ease, we are assuming the program will be invoked as prog <
infile > outfile int main ( int argc , const char ** argv ) {
char szCurrLine [MAX_LINE + 1] ;
while ( cin ) // Check for Error or End of File
{
cin.getline ( szCurrLine , MAX_LINE ) ;
// We are again checking for an error or end of file condition
// as well as whether we want the current line
if ( cin && wantLine ( szCurrLine ) )
{
cout << szCurrLine << endl ;
} /* endif */
} /* endwhile */
} /* int main ( int argc , const char ** argv ) */
bool wantLine ( const char * cszLine )
{
// Whatever testing you want goes here
return true ;
} /* bool wantLine ( const char * cszLine ) */
=============================================================
---
þ KWQ/2 1.2i þ ...had this been an actual emergency, we would flee in
terror, a
---------------
* Origin: St. Louis Users Group (1:100/4)
|