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. Inputing data from .txt to array.

Inputing data from .txt to array.

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelp
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.
  • R Offline
    R Offline
    Ramper
    wrote on last edited by
    #1

    I have a program that is able to take the numbers out of the .txt if it is just a list of numbers. Problem is, I have a file with Names before the grades. I believe i need to set up another array inside the first one to fill with names. The .txt file will look like: Name grade grade grade grade grade grade grade grade grade grade Name ... Have 15 Names with 10 grades under each. I guess what i'm trying to do is take the strings out of the file. Is there a way to take the strings(there is a string every 11 lines) Here is what i have now: #include #include #include #include #include #include using namespace std; const int TESTS = 10; const int STUDENTS = 15; void displayGrades( int [][TESTS] ); void getGrades( int [][TESTS]); int main() { int data[STUDENTS][TESTS] = {0}; getGrades( data ); cout <> data[student][test]; } } } void displayGrades( int data[][TESTS] ) { double testTotal = 0.0; double classTotal = 0.0; double squared = 0.0; double var = 0.0; double sdev = 0.0; int mxm = data[0][0]; int min = data[0][0]; cout << "\nGrade summary" << endl; cout << "--------------" << endl; cout << left << setw(7) << "Student" << right << setw(5) << right << "Ex1" << setw(7) << "Ex2" <

    B 1 Reply Last reply
    0
    • R Ramper

      I have a program that is able to take the numbers out of the .txt if it is just a list of numbers. Problem is, I have a file with Names before the grades. I believe i need to set up another array inside the first one to fill with names. The .txt file will look like: Name grade grade grade grade grade grade grade grade grade grade Name ... Have 15 Names with 10 grades under each. I guess what i'm trying to do is take the strings out of the file. Is there a way to take the strings(there is a string every 11 lines) Here is what i have now: #include #include #include #include #include #include using namespace std; const int TESTS = 10; const int STUDENTS = 15; void displayGrades( int [][TESTS] ); void getGrades( int [][TESTS]); int main() { int data[STUDENTS][TESTS] = {0}; getGrades( data ); cout <> data[student][test]; } } } void displayGrades( int data[][TESTS] ) { double testTotal = 0.0; double classTotal = 0.0; double squared = 0.0; double var = 0.0; double sdev = 0.0; int mxm = data[0][0]; int min = data[0][0]; cout << "\nGrade summary" << endl; cout << "--------------" << endl; cout << left << setw(7) << "Student" << right << setw(5) << right << "Ex1" << setw(7) << "Ex2" <

      B Offline
      B Offline
      benjymous
      wrote on last edited by
      #2

      So what's your actual problem? Does it fail to compile? Does it crash? Does it just act weird? Is there a particular part that you know isn't working properly? Have you tried stepping through that part in a debugger? If you can isolate the particular part that's giving you a problem, let us know, and we might be able to help

      -- Help me! I'm turning into a grapefruit! Buzzwords!

      R 1 Reply Last reply
      0
      • B benjymous

        So what's your actual problem? Does it fail to compile? Does it crash? Does it just act weird? Is there a particular part that you know isn't working properly? Have you tried stepping through that part in a debugger? If you can isolate the particular part that's giving you a problem, let us know, and we might be able to help

        -- Help me! I'm turning into a grapefruit! Buzzwords!

        R Offline
        R Offline
        Ramper
        wrote on last edited by
        #3

        there is no problem with the code that i posted. The problem i am facint is that the posted code will only read a list of integers without a student name. The .txt i need to read from is supposed to have the student name then 10 grades after then another name and another 10 grades. Don't know how to retrieve the name. Thanks

        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