•
•
•
•
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
![]() |
•
•
Join Date: Sep 2004
Posts: 7
Reputation:
Rep Power: 0
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.
#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: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,691
Reputation:
Rep Power: 36
Solved Threads: 877
•
•
Join Date: Sep 2004
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
This is a piece of the data file.
<< moderator edit: added code tags: [code][/code] >>
tttttttfft 3685 ttftttttft 2525 ttftfffttt 3689 ttfffftttt 3644 fftttffttt 2505 fffffttttt 2523 tttttttttf 1254 tttttttttt 5255 fffffffftt
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,691
Reputation:
Rep Power: 36
Solved Threads: 877
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];
}•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,691
Reputation:
Rep Power: 36
Solved Threads: 877
-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:
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:
Rep Power: 0
Solved Threads: 0
#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: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,691
Reputation:
Rep Power: 36
Solved Threads: 877
•
•
Join Date: Sep 2004
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
I am getting a blank page
<< moderator edit: added code tags: [code][/code] >>
#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;
}![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- 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



Linear Mode