nypran, looking at your original post, I see a mistake that beginners commonly make.
In programming, you have to be very precise. That means following the instructions of the assignment
to the letter. Usually the professor has carefully worded the assignment and every word matters. Let's look at the first few lines of your function:
1 2
|
bool senderFilter(char *logFileName, char *resultFileName, const char *sender)
{
|
So far so good. You've declared it exactly as asked.
const char sender = 0702-235689;
That's wrong. The sender is specified in the parameter called sender above.
1 2
|
int x = 0;
ifstream input("smslog_eng.txt");
|
That's wrong. The input file is specified in the logFileName parameter.
1 2 3 4 5
|
if (!input)
{
cerr << "File 'smslog_eng.dat' does not open!\n";
exit(1);
}
|
The instructions say that you should return false if there is a problem, not exit.
To get this stuff right and do it efficiently, you have to read the problem very carefully and do exactly what it asks.
I am writing a function that reads the text file “smslog_eng.txt”
and creates a new file containing all posts coming from the phone
number 0702-235689. |
As
Handy Andy said, please post an example (just a few lines should be enough" of the input file. We can't help you filter out the lines if we don't know what their format is.
Also, I suspect that the general solution should NOT read the entire input file and then filter it out. That wastes lots of memory. Instead, open
both input and output files. Then the function should:
1 2 3 4 5
|
readOneRecord;
if (theRecord matches theSender) {
writeTheRecord;
}
repeat until end of file.
|