Hi,
I have a text file that contains data seperated by a tab. I know that there are 26 columns but the number of rows are unknown b/c the file is huge. I need to traspose the data so I wrote the following script. I open the data file 26 times and each time it changes the column into a row. I know that the problem is in the statement of
datafile.open("sample.txt"); is the problem. I would appreciate if someone can help.
Thanks
#include <fstream>
#include <iomanip>
#include <iostream>
int main()
{
using namespace std;
ifstream datafile;
ofstream outdatafile;
char c,y1;
int i,j;
//datafile.open("sample.txt");
outdatafile.open("outdatasample.txt");
//datafile.get(c);
i=0;
j=0; // The total number of individuals
while (j <= 26)
{
datafile.open("sample.txt");
datafile.get(c);
cout<<c;
j++;
//cout<<j<<endl;
while (!datafile.eof())
{
//cout<<j<<endl;
i=0;
while (c!='\n')
{
if (isspace(c))
{
}
else
{
i++;
if (i==j)
{
y1=c;
datafile.get(c);
outdatafile<<y1<<'\t';
} // if
} //else
datafile.get(c);
} // while \n
datafile.get(c);
} //while eof
outdatafile<<'\n';
datafile.close();
}// while j
outdatafile.close();
system("pause");
return 0;
}//main