Hello to everybody,
I am a c++ beginner, and I want to do a program that reads a file with a column with numbers, "finds" the repeated numbers and write the repetitions on other file. For example, I have a file like this:
Input file:
6
5
4
4
7
5
6
6
6
6
1
And I want the output to be:
6 0R
5 0R
4 1R
7 0R
5 0R
6 3R
1 0R
I've done the following program:
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
int i=0;
int igual=0;
int array[30];
ifstream inFile;
ofstream outFile;
inFile.open("teste.txt");
outFile.open("escrita.txt");
while (inFile)
{
for (i=0;i<=10;i++)
{
inFile >> array [i];
if (array[i]==array[i+1])
{
igual++;
}
else
{
outFile << array [i] << " " << igual <<"R"<< endl;
igual=0;
}
}
i++;
}
inFile.close();
outFile.close();
return 0;
}
But the output is:
6 0R
5 0R
4 0R
4 0R
7 0R
5 0R
6 0R
6 0R
6 0R
6 0R
1 0R
6 0R
5 0R
4 1R
7 0R
5 0R
6 3R
1 0R
Where the bolt values are what I want, but how can I get reed of the first zeros?
What am I doing wrong?
Thanks a lot for your help, in advance!