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;
}

How about instead of reading all of the input files in at once, read them in one at a time and have a counter for later.

bool repeat=false
int count=-1
in >> x;
count++;

Then you can make the comparisons one by one and then just write the array to the file.

for(int i=0; i<=count; i++)
{
if(x==outarray[i])
repeat=True
}


if(repeat==false)
outarray[count]=x;
repeat=false;

This code will not compile and its a little sloppy but ill let you work with it. you need to put it in a loop so you can read in multiple letters and fit it to how you want it, but i hope this helps. Im not sure if this is what your looking for. your above description says you want a deleterepeat function but this is an alternative way to look at the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.