Hello I need to write a c++ program that requires a function called DeleteRepeat and prompts the user to input the name of a text file and outputs the new data in a new file. For example, the content of the text file that the user inputs is " b f e d b r e " and the new text file should be " b f d r ". Each letter is separated by a space. I keep getting error in my code. Any help would be greatly appreciated.
#include <iostream>
#include <fstream>
using namespace std;
void deleterepeat ( int a[], int& number_used );
void fillarray(int a[], int size, int& numberUsed);
int main()
{
const int MAX = 77;
ifstream fin;
ofstream fout;
int a[MAX], numberUsed;
fillarray(a, MAX, numberUsed);
deleterepeat(a,numberUsed);
for ( int i = 0; i < numberUsed; i++)
{
fout << "haha" << a[i];
}
cout << endl << endl;
fin.close();
fout.close();
return 0;
}
void fillarray(int a[], int size, int& numberUsed)
{
ifstream fin;
ofstream fout;
char filename[49];
int next, index = 0;
cout << " Enter a file name: ";
cin >> filename;
fin.open ("filename");
fout.open ("hmm.txt");
fin >> next;
while ((next != '\n') && (index < size))
{
a[index] = next;
index++;
fin >> next;;
}
numberUsed = index;
}
void deleterepeat(char a[], int& numberUsed)
{
for ( int i = 0; i < numberUsed; i++ )
{
for ( int j = i+1; j < numberUsed; j++ )
{
if (a[i] == a[j])
{
for ( int k = j; k < numberUsed; k++)
a[k] = a[k+1];
numberUsed--;
}
}
}
a[numberUsed] = 0;
}