Jump to content
xisto Community
Sign in to follow this  
xboxrulz1405241485

Isbn Decoding Issue

Recommended Posts

Hey guys,

 

I'm to write an ISBN decoder. However, I think I'm getting some incrementaling issue.

 

Posted Image

 

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;}
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;}
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,

xboxrulz

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.