Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to read data from a file... and store in separate string arrays. i know how to read the whole file into one array. but i need to read 10 lines and store in one array and another 10 lines and store in another array.. likewise 8 times.please help :)
Posted

well, if new line is the indicator of your one line, then count 10 new line, when you would reach the 10th new line you will start storing in your next array.
 
Share this answer
 
Hi there,

use getline api and read the each line from the file and maintain the count to read the lines from file.
if counts reach 10 means stop adding into first CStringArray. If the count starts 11, so start adding into another CString Array.

like wise you can split.

regards
Ranjith
 
Share this answer
 
Comments
Sith Indunil 26-Dec-12 5:49am    
but still i used getline function inside a for loop: and can i use if statement to check the incriment and give anothe array? eg: if(a > 11 && a < 22)
ranjithkumar81 26-Dec-12 6:21am    
for example:
declare int count variable in global;
open the file
if(file Handle != NULL)
do
{
read the line from file
add lines into CString array
count++;

if(count == 11)
add the lines(data) into another array
else if(count == 21)
add the lines(data) into another array
else if(count == 31)
add the lines(data) into another array
else
add the lines(data) into another array.

}while(fileHandle != EOF)


You may try this method....
Sith Indunil 1-Jan-13 0:57am    
while( !lo.eof())
{
getline(lo,arr1[i]);

if( i == 11)
{
getline(lo,arr2[i]);
}

else if( i == 22)
{
getline(lo,arr3[i]);
}

else if( i == 33)
{
getline(lo,arr4[i]);
}

else if( i == 44)
{
getline(lo,arr5[i]);
}

else if( i == 55)
{
getline(lo,arr6[i]);
}

else if( i == 66)
{
getline(lo,arr7[i]);
}
i++;
}


this thing doesnt work :/ any idea?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900