store data in arrays
-
Hi, I'm trying to read in a file of the type: Col1 Col2 Col3 Col4 Col5 Col6 .01 6438. 41.74 8753. 1.3596159.07 .20 6257. 42.05 8811. 1.4082155.84 .40 6159. 42.98 8987. 1.4590146.71 .60 6156. 44.57 9283. 1.5081133.16 .80 6242. 46.84 9707. 1.5551117.11 1.00 6415. 49.87 10265. 1.6002100.41 It is a text file and I want to store each of the columns in an array. The file is not tab delimited. The columns are separated by spaces. However col5 is accurate to 4 decimal places and joins col6 with the first number read as 159.07. How can I sort the data into arrays? Thanks kash
-
Hi, I'm trying to read in a file of the type: Col1 Col2 Col3 Col4 Col5 Col6 .01 6438. 41.74 8753. 1.3596159.07 .20 6257. 42.05 8811. 1.4082155.84 .40 6159. 42.98 8987. 1.4590146.71 .60 6156. 44.57 9283. 1.5081133.16 .80 6242. 46.84 9707. 1.5551117.11 1.00 6415. 49.87 10265. 1.6002100.41 It is a text file and I want to store each of the columns in an array. The file is not tab delimited. The columns are separated by spaces. However col5 is accurate to 4 decimal places and joins col6 with the first number read as 159.07. How can I sort the data into arrays? Thanks kash
It is really quite simple. Use the Find() fn in CString to look for the spaces and extract the data between spaces for col 1 thru 4 using the CString::Mid(..) fn Then use the Find() to look for the decimal point after the 4th space and count over 4 positions from there to determine the end of the 5th column and the start of the 6th column. Keep extracting data as needed. Repeat until the file is complete. Art
-
It is really quite simple. Use the Find() fn in CString to look for the spaces and extract the data between spaces for col 1 thru 4 using the CString::Mid(..) fn Then use the Find() to look for the decimal point after the 4th space and count over 4 positions from there to determine the end of the 5th column and the start of the 6th column. Keep extracting data as needed. Repeat until the file is complete. Art
-
Hi, I'm trying to read in a file of the type: Col1 Col2 Col3 Col4 Col5 Col6 .01 6438. 41.74 8753. 1.3596159.07 .20 6257. 42.05 8811. 1.4082155.84 .40 6159. 42.98 8987. 1.4590146.71 .60 6156. 44.57 9283. 1.5081133.16 .80 6242. 46.84 9707. 1.5551117.11 1.00 6415. 49.87 10265. 1.6002100.41 It is a text file and I want to store each of the columns in an array. The file is not tab delimited. The columns are separated by spaces. However col5 is accurate to 4 decimal places and joins col6 with the first number read as 159.07. How can I sort the data into arrays? Thanks kash
You could try attending class
-
CString sAllData(".01 6438. 41.74 8753. 1.3596159.07 "); CString sCol_1[10]; CString sCol_2[10]; CString sCol_3[10]; CString sCol_4[10]; CString sCol_5[10]; CString sCol_6[10]; int iPos1= 0; int iPos2= 0; for(int i=0; i<10; i++) { iPos2 = sAllData.Find(" ",iPos1); if(iPos2<0)break; sCol_1[i] = sAllData.Mid(iPos1, iPos2 - 0); //.01 iPos1 = sAllData.Find(" ",iPos2+1); if(iPos1<0)break; sCol_2[i] = sAllData.Mid(iPos2+1, iPos1 - iPos2); //6438. iPos2 = sAllData.Find(" ",iPos1+1); if(iPos2<0)break; sCol_3[i] = sAllData.Mid(iPos1+1, iPos2 - iPos1); //41.74 iPos1 = sAllData.Find(" ",iPos2+1); if(iPos1<0)break; sCol_4[i] = sAllData.Mid(iPos2+1, iPos1 - iPos2); //8753.1 iPos2 = sAllData.Find(".",iPos1+1); if(iPos2<0)break; int iPosCol5End = iPos2 + 4; sCol_5[i] = sAllData.Mid(iPos1+1, iPosCol5End - iPos1); //1.3596 iPos1 = sAllData.Find(" ",iPosCol5End+1); if(iPos1<0) break; sCol_6[i] = sAllData.Mid(iPosCol5End+1, iPos1-iPosCol5End); //159.07 CString sRow; sRow.Format("Row[%d] data:\n%s\n%s\n%s\n%s\n%s\n%s",i ,sCol_1[i] ,sCol_2[i] ,sCol_3[i] ,sCol_4[i] ,sCol_5[i] ,sCol_6[i]); AfxMessageBox(sRow); } Art