I’m pulling my hair out lol
I have some spare time this weekend and I want to write a program that will search for duplicate proxies (in a text file) and delete any (if found).
My first idea was to place the first proxy in a temp variable
Code:
inFile >> buffer;
proxy = buffer;
Then, do a string compare
Code:
if (strcmp(proxy, buffer) = = 0 )
{
cout << "duplacate found!" << endl;
…more code to delete proxy
}
But as the program parses through the test file, how do I move to the next proxy to compare while looping through the list one less each time?
The program sounds so simple to code, any ideas?
Code:
#include <fstream.h>
#include <stdlib.h>
#include <iomanip.h>
#include <string.h>
using namespace std;
int main()
{
const int MAXLENGTH = 50; // maximum file name length
char filename[MAXLENGTH]; // put the filename up front
char proxy[50];
char buffer[50];
ifstream inFile;
cout <<"enter the file name" <<endl;
cin >> filename;
strcat ( filename, ".txt");
inFile.open(filename, ios::nocreate | ios::out | ios::in);
if (inFile.fail())
{
cout << "ERROR opening file: " << filename << endl;
system("pause");
exit(1);
}
while(inFile)
{
//inFile.getline(buffer, MAXLENGTH);
// ^ different approaches, tried but this excepts white spaces…no good
inFile >> buffer;
cout << "buffer " << buffer << endl; // for display only while error testing
cout <<"proxy " <<proxy <<endl; // for display only
if (strcmp(proxy, buffer) == 0 )
cout << "*****duplacate found******" << endl;
//extra code will be added
//this will only loop once. I know I will have to create a nested loop
}
inFile.close();
system("PAUSE");
return 0;
}