I have a code:
using namespace std;
int main()
{
char Filename[100];
char st[100][100];
char *argv[100];
std::ifstream infile("data.txt");
std::freopen("output.xls","w",stdout);
if (!infile)
{
cout << " Input file Could not open file." << endl;
return 1;
}
std::string line;
while (std::getline(infile,line))
{
int a;
int length=line.size();
for(a=0;a<=length;a++)
{
Filename[a]=line[a];
}
// one D array to 2D array
int b=0;
int l=0;
strcpy(st[0],"0");// for erase previous value
//cout<<st[0]<<endl;
for(int j=0;j<=a;j++)
{
if (Filename[j]==' ')
{
b++;
l=0;
strcpy(st[b],"0");// for erase previous value
}
else
{
st[b][l]=Filename[j];
l++;
}
} //..........
// 2D array to reffarence array.
for(int k=0;k<=b;k++)
{
argv[k]=&st[k][0];
cout<<argv[k];// or cout<<st[k]; i get same
cout<<"\t";
}
cout<<endl;
//..............
// Do whatever with the array content
}
infile.close();
return 0;
}
the datafile is:(one space between two word)
testCore 100 100 400 5000 5000 “/end of line”
testCo 1 4 4 100 100 “/end of line”
tcore 1 3 4 5 20 “/end of line”
core 2 3 4 200 4 “/end of line”
my output is:

what I want: I want read the data file line by line(it is important) and separate each word after reading one line,then read another line. But the problem is in output in first word of every-line (in every word of first line also)it give garbage output. and there is problem in 2nd column also. What is the problem of my code? Anyone have any correction?
You’re creating a char array of size 100, which is uninitialised. Then, you’re only ever reading 3-8 chars into it. but you’re printing out the entire buffer, including the uninitialised elements.