Guest_imported
New member
- Jan 1, 1970
- 0
I'm trying to read in a large file, after is read, I have to get rid of anything that is not a word and then count the number of words. The first part I tried to do with strtok(), I read in the file using getline() so that it reads it one line at a time, then I send that input into the tokenizer. After that, I send the "filtered" string to an output file.
For some reason, my output file has repeated lines of text. There are some lines that don't even get tokenized! can anyone help?
Here's what I have so far...
For some reason, my output file has repeated lines of text. There are some lines that don't even get tokenized! can anyone help?
Here's what I have so far...
Code:
#include <fstream.h>
#include <cstring>
#include <iostream>
char*ptr;
using std::endl;
void main(void)
{
fstream NameFile,outFile;
char Input[81];
NameFile.open("arm95.txt", ios::in);
if (!NameFile)
{
cout << "File open error!" << endl;
return;
}
outFile.open("arm95output.txt", ios::out);
while (!NameFile.eof())
{
NameFile.getline(Input,81); // use \n as a delimiter
ptr = strtok(Input, "1234567890!@#$%^&*()_+-=;:',.<>|}{[]`~");
while (ptr != NULL){
cout << ptr << endl;
ptr = strtok(NULL," ");
outFile << Input << endl;}
//cout << Input << endl;
}
NameFile.close();
outFile.close();
}