Hi all,
I'm having issues reading in a file correctly. Yes, this is a school project but I only need help with a portion of it. I am only allowed iostream and fstream as libraries. I know exactly where the issue is but cannot seem to fix it.
Here is the file format :
Enterprise 89502
2014 Toyota Tacoma 115.12 {gps} 1
2012 Honda CRV 85.10 {camera lidar} 0 Mike
2011 Toyota Rav4 65.02 {} 0 Oscar
2009 Dodge Neon 45.25 {camera lidar radar} 1
2015 Ford Fusion 90.89 {lidar} 0 Juliet
Here is the output I receive when I read it in:
2014 Toyota Tacoma 115.12 2012 0 0\356\277\357\376
2014 Toyota Tacoma 115.12 2012 0 0\356\277\357\376
2014 Toyota Tacoma 115.12 2012 0 0\356\277\357\376
2014 Toyota Tacoma 115.12 2012 0 0\356\277\357\376
2014 Toyota Tacoma 115.12 2012 0 0\356\277\357\376
The issue is that the program tries to read in t_sensor as a boolean when there is a space between gps and lidar i.e. {gps lidar}
I need to create a catch for this.
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
|
char charCheck;
char fileName[256];
ifstream infile;
infile.open("HighTechAgency.txt");
int t_year;
char t_make[256], t_model[256];
float t_price;
char t_sensor[256];
bool t_available;
char t_owner[256];
char t_agency[256];
int t_zip;
int sensorCount;
int loopCount;
char * sensorSpot;
infile >> t_agency >> t_zip;
cout << t_agency << " " << t_zip << endl;
for(int i = 0; i < 5; i++) {
infile >> t_year >> t_make >> t_model >> t_price;
charCheck = infile.peek();
sensorCount = 0;
for(int i = 0; i < 3; i++) {
if(charCheck != 125) {
sensorCount = 1;
infile >> t_sensor;
loopCount = 0;
sensorSpot = t_sensor;
if(*sensorSpot != 125) {
for(sensorSpot = t_sensor; *sensorSpot != 125 && *sensorSpot != '\0'; sensorSpot++) {
loopCount = 1;
}
}
}
}
infile >> t_available;
if(!t_available) {
infile >> t_owner;
}
cout << t_year << " " << t_make << " " << t_model << " " << t_price << " " << t_sensor << " " << t_available << " ";
if(!t_available) {
cout << t_owner << endl;
}
else {
cout << endl;
}
}
}
|