| | |
Please help with data file and array
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2004
Posts: 7
Reputation:
Solved Threads: 0
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.
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.
C++ Syntax (Toggle Plain Text)
#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; }
•
•
Join Date: Sep 2004
Posts: 7
Reputation:
Solved Threads: 0
This is a piece of the data file.
<< moderator edit: added code tags: [code][/code] >>
C++ Syntax (Toggle Plain Text)
tttttttfft 3685 ttftttttft 2525 ttftfffttt 3689 ttfffftttt 3644 fftttffttt 2505 fffffttttt 2523 tttttttttf 1254 tttttttttt 5255 fffffffftt
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.
C++ Syntax (Toggle Plain Text)
for (int c = 0; c<maxstudents; c++) { infile>>studentid[c] >> quiz[c]; }
-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:
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
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:
C++ Syntax (Toggle Plain Text)
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
•
•
Join Date: Sep 2004
Posts: 7
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#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; }
•
•
Join Date: Sep 2004
Posts: 7
Reputation:
Solved Threads: 0
I am getting a blank page
<< moderator edit: added code tags: [code][/code] >>
C++ Syntax (Toggle Plain Text)
#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; }
![]() |
Similar Threads
- Reading file input into an array (C++)
- help me to read my data file:(( (C)
- input data from a file into an Array (C)
- data file help (C)
Other Threads in the C++ Forum
- Previous Thread: where to get C compiler
- Next Thread: C++ help
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






