Problem with Program, input/output

This is my input assigned:
// ID Name Address St Zip Majr Minr Rk QCA AltQCA Crd Hrs
135792468 Wayne,John Duke 101 Hollywood Way CA 40815 CS MATH 10 3.2667 4.0000 49 15

this is my code thus far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <fstream>#include <iomanip>#include <string>#include <cmath>#include <iostream>#include <cctype> using namespace std; struct Program{	char Number, Name;	char Code;	char Major, Minor;	int Rank;	char Address;	};int i=1,q=0, y=0; char t = '\t';Program ID[9],Student[20],Street[25],Home[2],Zip[5],First[4],Second[4],Status[2];  //function prototypesvoid readID(ifstream& In, ofstream& Out, int q);void readName(ifstream& In, ofstream& Out, int q);void readRank(ifstream& In, ofstream& Out, int q);void readMinor(ifstream& In, ofstream& Out, int q);void readMajor(ifstream& In, ofstream& Out, int q);void readState(ifstream& In, ofstream& Out, int q);void readZip(ifstream& In, ofstream& Out, int q);void readAddress(ifstream& In, ofstream& Out, int q);  void main(){  	double QCA, AltQCA;    int QualCred, HrsAtt;	ifstream In("students1.txt");	ifstream InData("courses1.txt");	ofstream Out("qca1.txt");	Out<<fixed<<showpoint;	Out<<"QCA Calculation"<<endl;	Out<<"__________________________________________________________"<<endl;	Out<<"ID Number    Name      Major     Minor    Rank"<<endl; 	In.ignore(255,'\n');	readID(In,Out,q);	readName(In,Out,q);	readMajor(In,Out,q);   	In>>QCA>>AltQCA;	In>>QualCred>>HrsAtt; 	In.close();	InData.close();	Out.close();}//functions to read student.datvoid readID(ifstream& In, ofstream& Out, int q){	In.get(ID[q].Number);	//reading the ID Number of the student	for(i=0;i<9;i++)	{	Out<<ID[q].Number;	In.get(ID[q].Number); 	}	Out<<' ';} void readName(ifstream& In, ofstream& Out, int q){	In.get(Student[q].Name);	for(i=0;i<20;i++)	{	Out<<Student[q].Name;	In.get(Student[q].Name);	}	Out<<' ';}  void readMajor(ifstream& In, ofstream& Out, int q){	In.get(First[q].Major);	for(i=0;i<5;i++)	{		Out<<First[q].Major;		In.get(First[q].Major);	}}#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <iostream>
#include <cctype>

using namespace std;
 
struct Program
{
	char Number, Name;
	char Code;
	char Major, Minor;
	int Rank;
	char Address;
	};
int i=1,q=0, y=0; 
char t = '\t';
Program ID[9],Student[20],Street[25],Home[2],Zip[5],First[4],Second[4],Status[2];


//function prototypes
void readID(ifstream& In, ofstream& Out, int q);
void readName(ifstream& In, ofstream& Out, int q);
void readRank(ifstream& In, ofstream& Out, int q);
void readMinor(ifstream& In, ofstream& Out, int q);
void readMajor(ifstream& In, ofstream& Out, int q);
void readState(ifstream& In, ofstream& Out, int q);
void readZip(ifstream& In, ofstream& Out, int q);
void readAddress(ifstream& In, ofstream& Out, int q);


void main()
{  	double QCA, AltQCA;
    int QualCred, HrsAtt;
	ifstream In("students1.txt");
	ifstream InData("courses1.txt");
	ofstream Out("qca1.txt");
	Out<<fixed<<showpoint;
	Out<<"QCA Calculation"<<endl;
	Out<<"__________________________________________________________"<<endl;
	Out<<"ID Number    Name      Major     Minor    Rank"<<endl;
	
	In.ignore(255,'\n');
	readID(In,Out,q);
	readName(In,Out,q);
	readMajor(In,Out,q);
   	In>>QCA>>AltQCA;
	In>>QualCred>>HrsAtt;
	
	In.close();
	InData.close();
	Out.close();
}
//functions to read student.dat
void readID(ifstream& In, ofstream& Out, int q){
	In.get(ID[q].Number);
	//reading the ID Number of the student
	for(i=0;i<9;i++)
	{
	Out<<ID[q].Number;
	In.get(ID[q].Number);
	
	}
	Out<<' ';
}

void readName(ifstream& In, ofstream& Out, int q){
	In.get(Student[q].Name);
	for(i=0;i<20;i++)
	{
	Out<<Student[q].Name;
	In.get(Student[q].Name);
	}
	Out<<' ';
}


void readMajor(ifstream& In, ofstream& Out, int q){
	In.get(First[q].Major);
	for(i=0;i<5;i++)
	{
		Out<<First[q].Major;
		In.get(First[q].Major);
	}
}


And my output...
QCA Calculation
__________________________________________________________
ID Number Name Major Minor Rank
135792468 Wayne,John Duke 101 ollyw




so my question is, how do i, when bringing in the input, "skip over" the address, state, and zip code to read and output the major, minor, and rank? Also I need to make sure the remaining information, QCA AltQCA Crd Hrs, are read and stored for future use. Any help is appreciated, thank you!
Last edited on
Well one thing that you can do is a getline to read in each line and then parse the fields. For instance use getline to build the string with the columns and stringstream to break that first line up into the separate fields that need to be processed. That becomes the names of each item in each record. Then use getline again in a loop to process each line of data. From there you have to design a way to figure out how each part of each line relates to each column. You might want to consider making that comma separated though otherwise I don't know of how you are going to figure out how to break the lines up into appropriate pieces since the address field has spaces between each part.
sooo would i do something like this...

string data;
getline(In, data);

then use stringstream to break that into what i want?




Yes.
http://www.cplusplus.com/forum/general/17771/
http://www.cplusplus.com/forum/beginner/10756/

Of course you can use whatever delimiter you wish it is just that commas are pretty common. In your case your input file is in a terrible format so I hope you can change that to make your life easier.
Topic archived. No new replies allowed.