Thread: Parallel Arrays

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    81

    Parallel Arrays

    Hey, I need some help with reading in data into 3 parallel arrays. 2 of the arrays are integers and the last one is a character string. I need to be able to read in all the data from the fileand store it into the arrays. The format of the input file is like this:

    526334512 2665312 Jones, Julie Claire
    264910093 2689022 Morgan, James Walter
    587194309 5441234 Allen, Mary Ann
    ... ... ...

    The code that I have so far(that does not work) is this:

    Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <iomanip.h>
    #include <ctype.h>
    #include <stdlib.h>
    
    //Global variables
    ifstream infile;
    ofstream outfile;
    
    typedef char str[30];
    
    int main()
    {
    int n[30],m[30];
    str name[30];
    
    	infile.open("in599A.dat");
    	while(infile)
    	{
    		for(int i=0;i<22;i++)
    		{infile >> n[i] >> m[i];
    		cout << n[i] << endl << m[i] << endl;
    		infile >> name[i];
    		cout << name[i] << endl;
    		}
    		
    
    	}
    
    
    
    
    	return 0;
    }

  2. #2
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Well, first of all

    #include <iostream.h>
    #include <fstream.h>
    #include <stdlib.h>
    should be
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    using namespace std;

    and why are declaring the global variables? just declare them in the main()...

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    81
    I'm going to need them later on in my program... so I thought anyway

    Basically, I would like to know the syntax for reading the data in and storing it into the arrays. I tried to print out what I had using the code above and it wasn't printing out correctly

  4. #4
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    well, it looks fine to me, but then again, don't trust me .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parallel arrays
    By beginner1 in forum C Programming
    Replies: 2
    Last Post: 05-19-2009, 08:53 AM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  4. Parallel Arrays with Multiple Arrays
    By Billye Scott in forum C++ Programming
    Replies: 0
    Last Post: 03-02-2002, 11:14 PM
  5. parallel arrays
    By KeeNCPP in forum C++ Programming
    Replies: 1
    Last Post: 10-18-2001, 09:56 PM