User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 401,689 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,743 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 2127 | Replies: 10
Reply
Join Date: Sep 2004
Posts: 7
Reputation: christyj5 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
christyj5 christyj5 is offline Offline
Newbie Poster

Please help with data file and array

  #1  
Oct 5th, 2005
I am trying to infile my data file into two seperate arrays which are seperated by a white space in my file.
But I keep getting -86******* something number where my file is suppose to be any help will be very helpful. My first array which will read the student id is a one dimensional array and the second arry is a 2 dimensional arry which will read in the students answers to a true false test and the second col will be the total number correct for each true false question. Yeah and the answer key is suppose to be the last line in the 2 D array which is the first line in my data file.
#include<iostream>
#include <fstream>
#include "string"
using namespace std;
int main()
{
    const int maxstudents=50;
	const int maxcols=3;
	char quiz[maxstudents+1][maxcols];
    int studentid[maxstudents];

	ifstream infile;
    string inputfile;
	cout<<"Input filename"<<endl;
	cin>> inputfile;
	
	infile.open(inputfile.c_str());
	for (int c = 0; c<maxstudents; c++)
		infile>>quiz[maxstudents][c]; 
		for (int k=0; k<maxstudents; k++)
			infile>>studentid[k];
			
		    for (int j=0; j<maxstudents; j++)
				cout<<"studentid"<<j<<"\t"<<studentid[j]<<endl;
              for (int r=0; r<10; r++)
	         cout<<quiz[maxstudents][r]<<"\t";
           

return 0;
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,691
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 877
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Please help with data file and array

  #2  
Oct 6th, 2005
post the contents of the data file, or just a few lines if its too large. Your program is written to expect all student ids to be listed first, followed by all answers and lastly the total number correct for each student. But I doubt that is how they appear in the data file.
Reply With Quote  
Join Date: Sep 2004
Posts: 7
Reputation: christyj5 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
christyj5 christyj5 is offline Offline
Newbie Poster

Re: Please help with data file and array

  #3  
Oct 6th, 2005
This is a piece of the data file.

tttttttfft
3685 ttftttttft
2525 ttftfffttt
3689 ttfffftttt
3644 fftttffttt
2505 fffffttttt
2523 tttttttttf
1254 tttttttttt
5255 fffffffftt
<< moderator edit: added code tags: [code][/code] >>
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,691
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 877
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Please help with data file and array

  #4  
Oct 6th, 2005
where is the third column? Your program needs only one loop. maxcols is too small -- needs to be 1 more than the number of t/f test scores.
for (int c = 0; c<maxstudents; c++)
{
	infile>>studentid[c] >> quiz[c]; 
}
Reply With Quote  
Join Date: Sep 2004
Posts: 7
Reputation: christyj5 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
christyj5 christyj5 is offline Offline
Newbie Poster

Re: Please help with data file and array

  #5  
Oct 6th, 2005
i tried that and still got the -86 error
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,691
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 877
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Please help with data file and array

  #6  
Oct 6th, 2005
-86, is that a compile-time error or runtime error?
1. make sure maxstudents is not greater than the number of lines in the data file. There are better (and easier) ways to read the file without knowing the number of lines beforehand, but get this working first and you can refine your program later.

2. The output line is incorrect. It should look like this:
cout<<quiz[r]<<"\t";

If you still have problems after making the changes, repost your program. But those should fix it, at least it did in my version that I don't intend to post
Reply With Quote  
Join Date: Sep 2004
Posts: 7
Reputation: christyj5 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
christyj5 christyj5 is offline Offline
Newbie Poster

Re: Please help with data file and array

  #7  
Oct 6th, 2005
#include<iostream>
#include <fstream>
#include "string"

using namespace std;


 const int maxstudents=25;


int main()
{
   
	const int maxcols=4;
    char quiz[maxstudents+1][maxcols];
    int studentid[maxstudents];

	ifstream infile;
    string inputfile;
	cout<<"Input filename"<<endl;
	cin>> inputfile;
	
	infile.open(inputfile.c_str());
       

for (int c = 0; c<maxstudents; c++)
{
	infile>> studentid[c] >> quiz[c]; 
}

for (int r=0; r<maxstudents; r++)
      cout<<quiz[r]<<"\t";	
return 0;
}
<< moderator edit: added code tags: [code][/code] >>
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,691
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 877
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Please help with data file and array

  #8  
Oct 6th, 2005
const int maxcols=4;


Count the number of t's and f's in one of those lines. How many did you count? Less than 4 or more than 4. maxcols needs to be a minimum of (number of t's and f's) + 1 for the character array's null-terminator.
Reply With Quote  
Join Date: Sep 2004
Posts: 7
Reputation: christyj5 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
christyj5 christyj5 is offline Offline
Newbie Poster

Re: Please help with data file and array

  #9  
Oct 6th, 2005
I am getting a blank page

#include<iostream>
#include <fstream>
#include "string"

using namespace std;


 const int maxstudents=3;
int main()
{
   
	
	ifstream infile;
    string inputfile;
	cout<<"Input filename"<<endl;
	cin>> inputfile;
	
	infile.open(inputfile.c_str());
 

	char quiz[maxstudents+1][11];
    int studentid[maxstudents];
	
for (int c = 0; c<maxstudents; c++)
{
infile>> studentid[c] >> quiz[c]; 
}

for (int r=0; r<maxstudents; r++)
cout<<quiz[r]<<"\t"; 
return o;
}
<< moderator edit: added code tags: [code][/code] >>
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,691
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 877
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Please help with data file and array

  #10  
Oct 7th, 2005
visually verify the data file is correct -- no blank lines and every line has the same format.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 7:54 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC