Results 1 to 5 of 5

Thread: Any suggestions on how I should read in this file?.:Resolved:.

  1. #1

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Question Any suggestions on how I should read in this file?.:Resolved:.

    Hello everyone, I have a file set up like this:

    100 93
    43 30
    80 70
    ... ...
    these grades are seperated by a tab character, the first column is lab 1, the second column is lab 2, I want to seperate these 2 columns and manipulate them seperately, like, I will have to find the average of them, the mode of them, and the min and max of each lab, any idea's? I was trying to seperate them into 2 different arrays, but thats not working too well!
    Code:
    int array1[500];
    	int array2[500];
    	int one;
    	int two;
    	char ch;
    	char newline;
    	int i =0; 
    
    	while(!inFile.eof())
    	{
    		inFile >>one>>ch>>two>>newline;
    		array1[i] = one;
    		array2[i] = two;
    		i++;
    
    	}
    thanks!
    Last edited by voidflux; Dec 11th, 2003 at 12:41 AM.
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    Try this: when you try to read an integer, it will skip whitespaces and newline to get to the next one. You made it too hard :P

    Code:
    int array1[500];
    	int array2[500];
    	int one;
    	int two;
    	int i =0; 
    
    	while(!inFile.eof())
    	{
    		inFile >> one >>two;
    		array1[i] = one;
    		array2[i] = two;
    		i++;
    
    	}
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290
    wow! thank u so much! i've spent about 4 hours on this! dear god! i'm going to snap hah thanks again!
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Why even the temps?
    Code:
    int array1[500];
    int array2[500];
    int i =0; 
    
    while(!inFile.eof())
    {
    	inFile >> array1[i] >> array2[i];
    	++i;
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290
    they really weren't needed, at the time it just came to me to use temps for some reason, when this problem comes up on the final i'll discard of them! thanks!
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width