Hello All!
Back again! I've put the following together to edit a friend's files.bbs file
of particular text.
#include
#include
#include
#include
#include
#include
#pragma hdrstop
int main(int argc, char **argv)
{
char buff[81];
int cntr=0;
// Open the source and temporary output files for action.
cout << "Preparing to edit files.bbs. Please standby...\n";
ifstream infile("files.bbs");
if (!infile)
{
cout << "Cannot open files.bbs for input...\n";
getch();
return 1;
}
ofstream outfile("files.$$$");
if (!outfile)
{
cout << "Cannot open files.$$$ for output...\n";
getch();
infile.close();
return 1;
}
I've got the surrounding code to work reasonably well, but I can't seem to
et
this comparison to work. Anybody got any ideas? Is a case insensitive check
possible, or can I uppercase the incoming file line to make the comparison?
// Loop through the source file, checking each line for the
// offending text, and writing those that pass the "filter"
// to the output working file.
while (!infile.eof())
{
infile.getline(buff, sizeof(buff));
if (strstr(buff, "DESCRIPTION BY DIZMAN") == 0)
outfile << buff << endl;
else
cntr + 1;
}
infile.close();
outfile.close();
// Clean things up by removing the old source file
// and renaming the temporary work file.
if (remove("files.bbs") == 0)
{
printf("Removed %s.\n","files.bbs");
if (rename("files.$$$", "files.bbs") == 0)
printf("Renamed %s to %s.\n", "files.$$$", "files.bbs");
else
perror("rename");
}
else
perror("remove");
// Report lines deleted, if any.
if (cntr == 0)
cout << "No lines deleted in this action.\n";
else
cout << "Lines deleted in this action: " << cntr << "\n";
getch();
return 0;
}
Brian Lunergan
Nepean, ON
Canada
E-mail: blunergan@cyberus.ca / Fidonet: 1:163/335.44
Member: HTML Writers Guild
MS Site Builders Network -- Level 2
... Oh - you love cats too - want to swap a few recipes?
--- UNREG UNREG
---------------
* Origin: The Crystal Cave..., Nepean, Ontario, Canada (1:163/335.44)
|