ISBN Decoding issue
Author |
Message |
deltatux
|
Posted: Mon Feb 16, 2009 5:18 pm Post subject: ISBN Decoding issue |
|
|
Hey guys,
I'm to write an ISBN decoder. However, I think I'm getting some incrementaling issue.
code: |
int decode(FILE* fp, char* str, char* area, char* publisher, char* title){
// determine area
int area0;
bool found = false;
int digitsArea = 0;
for (digitsArea = 1; digitsArea <= 5; digitsArea++) {
// parse the first 'digits' chars in isbn into area0
area0 = 0;
for (int i = 0; i < digitsArea; ++i) {
area0 = area0 * 10 + (str[i] - '0');
cout << str[i] << endl; //debug output
}
if (registered(fp, area0)) {
found = true;
break;
}
}
if (!found) {
cout << "Area not found: " << area << endl;
return false;
}
std::stringstream aout;
aout << area0;
aout >> area;
// determine publisher
int pub0, digitsPub = 0;
for (digitsPub = digitsArea + 1; digitsPub <= 7; digitsPub++){
//parse the second set of 'digits' chars in isbn into pub0
pub0 = 0;
for (int i = digitsArea; i < digitsPub; i++){
pub0 = pub0 * 10 + (str[i] - '0');
cout << str[i] << endl; //debug output
}
if (registered(fp, area0, pub0)){
found = true;
break;
}
}
if (!found){
cout << "Publisher not found: " << publisher << endl;
return false;
}
std::stringstream pout;
pout << pub0;
pout >> publisher;
// determine title
int title0;
for (int digitsTitle = digitsPub + 1; digitsTitle <= 10; digitsTitle++){
//parse the third set of 'digits' chars in isbn into title0
title0 = 0;
for (int i = digitsPub; i < digitsPub; i++){
title0 = title0 * 10 + (str[i] - '0');
cout << str[i] << endl; //debug output
}
}
std::stringstream tout;
tout << title0;
tout >> title;
return true;
}
|
code: |
int registered(FILE* fp, int area, int publisher){
seekStart(fp);
ifstream in(fp);
while (in) {
int area0, minPublisher, maxPublisher;
in >> area0 >> minPublisher >> maxPublisher;
if (area0 == area) {
if (minPublisher <= publisher && publisher <= maxPublisher) return true;
}
}
return false;
}
|
code: |
int registered(FILE* fp, int area){
seekStart(fp);
ifstream in(fp);
while (in) {
int area0, minPublisher, maxPublisher;
in >> area0 >> minPublisher >> maxPublisher;
if (area0 == area) return true;
}
return false;
}
|
It looks like at the publisher section, it isn't incrementing properly, but I don't know why. Please help.
Thanks,
deltatux |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|