Hello! So my goal is to make a function that has a partially filled array of characters as a formal parameter and deletes all repeated letters from the array. So I just need to read a .txt file with it's contents as something like "11 A B C a b c a A g g t " and have the program spit back out "A B C a b c g t"
As of now my program spits back "1 A B C a b c "
I'd really appreciate any help on this.
Here is what I have...
#include <iostream>
#include <fstream>
using namespace std;
bool deleterepeat( char arraytocheck[], char lettertocheck, int length)
{
bool onlistflag = false;
{
for (int i = 0; i < length; i++)
{
if (arraytocheck[i] == lettertocheck)
{
onlistflag = true;
}
}
}
return onlistflag;
}
int main()
{
const int MAX = 15;
char inFile[MAX];
char clearedList[MAX];
int clearedlength = 0;
cout << "Choose a file: ";
cin.getline(inFile, 15);
ifstream in(inFile);
if(!in) {
cout << "Cannot open input file.\n";
return 1;
}
while(in) {
in.getline(inFile, MAX);
for (int i = 0; i < MAX; i++)
{
in >> inFile[i];
}
for (int i = 0; i < MAX; i++)
{
if (deleterepeat(clearedList, inFile[i], i) == false)
{
clearedList[clearedlength] = inFile[i];
clearedlength++;
}
}
for (int i = 0; i < clearedlength; i++)
{
cout << clearedList[i] << " ";
}
if(in) cout << inFile << endl;
}
cout << endl;
cin >> inFile;
in.close();
return 0;
}