Guest_imported
New member
- Jan 1, 1970
- 0
hi all,
I am having difficulty getting C++ to read
data into a char type 2 dimensional array from a "Data.text" file.I have work with one dimensional array before but not a two dimensional.So its new to me. The data file looks like this,
------------------------------------------------------
T1 T2 T3 T4 T5 T6 T7 T8
Gigalo, Donald 8 9 10 7 9 82 76 72
Lennon, John 6 8 9 7 8 68 74 83
Garriss, Tom 10 10 10 10 10 100 100 100
Marriss, Nick 9 8 9 8 9 90 80 90
Ivano, Erikas 6 5 4 0 0 65 58 34
-------------------------------------------------------
1.The first line from T1 all the way right to T8, I am able to get C++ to read it into char T[80]; successfully.
2. Now comes the problem. The problem I am having is getting C++ to read the last name Gigalo and all the names on that row down to Ivan and store it into a char type two dimension array.
I dont know if Im doing it right or what, but when I c-out it keeps printing out junk characters.
This is the code Im using to get C++ to read just the lastnames in and printing it out on screen.
3.What did I do wrong? please help.I have takin like a bottle of Advil now trying to alleviate my head-ache. Thnkx in advance.
-------------------------------------------------------
void main ()
{
ifstream Infile("data.txt"
char Lastname[9][10];
while(Infile)
{
for(int row=0;row<9;row++)
{
Infile.getline(Lastname[row],10,'\n');
}
}
for(int count1=0;count1<9;count1++)
{
for(int count2=0;count2<10;count2++)
{
cout<<Lastname[count1][count2];
}
}
}
------------------------------------------------
I am having difficulty getting C++ to read
data into a char type 2 dimensional array from a "Data.text" file.I have work with one dimensional array before but not a two dimensional.So its new to me. The data file looks like this,
------------------------------------------------------
T1 T2 T3 T4 T5 T6 T7 T8
Gigalo, Donald 8 9 10 7 9 82 76 72
Lennon, John 6 8 9 7 8 68 74 83
Garriss, Tom 10 10 10 10 10 100 100 100
Marriss, Nick 9 8 9 8 9 90 80 90
Ivano, Erikas 6 5 4 0 0 65 58 34
-------------------------------------------------------
1.The first line from T1 all the way right to T8, I am able to get C++ to read it into char T[80]; successfully.
2. Now comes the problem. The problem I am having is getting C++ to read the last name Gigalo and all the names on that row down to Ivan and store it into a char type two dimension array.
I dont know if Im doing it right or what, but when I c-out it keeps printing out junk characters.
This is the code Im using to get C++ to read just the lastnames in and printing it out on screen.
3.What did I do wrong? please help.I have takin like a bottle of Advil now trying to alleviate my head-ache. Thnkx in advance.
-------------------------------------------------------
void main ()
{
ifstream Infile("data.txt"
char Lastname[9][10];
while(Infile)
{
for(int row=0;row<9;row++)
{
Infile.getline(Lastname[row],10,'\n');
}
}
for(int count1=0;count1<9;count1++)
{
for(int count2=0;count2<10;count2++)
{
cout<<Lastname[count1][count2];
}
}
}
------------------------------------------------