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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Basic query regarding arrays/data sets

Basic query regarding arrays/data sets

Scheduled Pinned Locked Moved C / C++ / MFC
database
3 Posts 2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I am a musician who is trying to code an app for a project. I basically need to know how I can take a set of data integers saved in a file of some extension <.txt or whatever> that any user like myself can edit and save using notepad or such, and subsequently utilise these in my program. By way of explanation, the app is desired to generate scorefile data for use within a soft synth app and the scorefiles usually take the form of long screeds of largely repeated data values which are coded manually- holding back the popularlity of the software no end!!! If a set of pitch values could be saved in a file then these values could be called by an app to gen the score using them as a template. I appreciate this is a fairly non-technical query, but it is becoming a bit of a stumbling block at my end I would really appreciate a hand. I thank you for your time.

    P 2 Replies Last reply
    0
    • L Lost User

      I am a musician who is trying to code an app for a project. I basically need to know how I can take a set of data integers saved in a file of some extension <.txt or whatever> that any user like myself can edit and save using notepad or such, and subsequently utilise these in my program. By way of explanation, the app is desired to generate scorefile data for use within a soft synth app and the scorefiles usually take the form of long screeds of largely repeated data values which are coded manually- holding back the popularlity of the software no end!!! If a set of pitch values could be saved in a file then these values could be called by an app to gen the score using them as a template. I appreciate this is a fairly non-technical query, but it is becoming a bit of a stumbling block at my end I would really appreciate a hand. I thank you for your time.

      P Offline
      P Offline
      Philip Nicoletti
      wrote on last edited by
      #2

      If I understand your question correctly : 1) you have files with a bunch of integers in them 2) you want to read these integers into an array 3) (possibly) manipulate the integers 4) (possibly) write the integers out to file again One possible solution : At the top of your CPP file :

      #define MAX_RECORDS 1000 // max number of data integers

      int array[MAX_RECORDS]; // the array of data integers

      int numRecords; // actual number of integers
      // in the file

      To bring up a file open dialog and read in the data :

      CFileDialog ifile(TRUE,"txt",NULL,OFN_HIDEREADONLY,
      "text files|*.txt|all files|*.*||");

      int result = ifile.DoModal();

      if (result == IDOK)
      {
      CString info;
      info = ifile.GetPathName();

      ifstream infile;
      infile.open(info);

      numRecords = 0;

      while (!infile.eof())
      {
      if (numRecords == MAX_RECORDS) break;
      infile >> array[numRecords];
      numRecords++;
      }
      if (infile.eof()) numRecords--;

      infile.close();

      }

      to bring up a file save dialog and write the data integers to file :

      CFileDialog ofile(FALSE,"txt",NULL,OFN_OVERWRITEPROMPT,
      "text files|*.txt|all files|*.*||");

      int result = ofile.DoModal();

      if (result == IDOK)
      {

      CString info;
      info = ofile.GetPathName();

      ofstream outfile;
      outfile.open(info);

      for (int i=0; i<numRecords; i++)
      outfile << array[i] << "\n";

      outfile.close();

      }

      1 Reply Last reply
      0
      • L Lost User

        I am a musician who is trying to code an app for a project. I basically need to know how I can take a set of data integers saved in a file of some extension <.txt or whatever> that any user like myself can edit and save using notepad or such, and subsequently utilise these in my program. By way of explanation, the app is desired to generate scorefile data for use within a soft synth app and the scorefiles usually take the form of long screeds of largely repeated data values which are coded manually- holding back the popularlity of the software no end!!! If a set of pitch values could be saved in a file then these values could be called by an app to gen the score using them as a template. I appreciate this is a fairly non-technical query, but it is becoming a bit of a stumbling block at my end I would really appreciate a hand. I thank you for your time.

        P Offline
        P Offline
        Philip Nicoletti
        wrote on last edited by
        #3

        forgot 1 thing ... at the top of the CPP you also need to add the line :

        #include <fstream.h> // for file i/o

        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