Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. store data in arrays

store data in arrays

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kash
    wrote on last edited by
    #1

    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

    B J 2 Replies Last reply
    0
    • K 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

      B Offline
      B Offline
      Big Art
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • B Big 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

        K Offline
        K Offline
        Kash
        wrote on last edited by
        #3

        could you provide a code snippet to get me started?

        B 1 Reply Last reply
        0
        • K 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

          J Offline
          J Offline
          Joe Woodbury
          wrote on last edited by
          #4

          You could try attending class

          1 Reply Last reply
          0
          • K Kash

            could you provide a code snippet to get me started?

            B Offline
            B Offline
            Big Art
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups