compiles but wont run

I ran a simple program that had no errors or warnings when it compiles but when i try to run it i get windows generic message this program will need to close. Any suggestions. I am normally pretty good at debugging but not sure where to look when their is no errors. Any ideas at all.

thanks for any help

john
[330 byte] By [jpkirvan] at [2007-11-19 18:28:46]
# 1 Re: compiles but wont run
That happens all the time ;)
I'd need to look at the code.
mojo_jojo at 2007-11-9 0:55:43 >
# 2 Re: compiles but wont run
//////////////////////Main Program///////////////////////////////////////////////

#include <iostream>
#include <fstream>
#include <cstring>
#include "ISBN.h"
#include "Book.h"
using namespace std;

const int NUMBER_OF_BOOKS = 15;

void check_isbn_class();
void check_book_class();

int main() {
check_isbn_class();
check_book_class();
return 0;
}

void check_isbn_class() {
char isbns[13][14];
int index=0;
strcpy(isbns[index++], "1-57676-074-X");
strcpy(isbns[index++], "0-12-597121-2"); // correct check digit is 4
strcpy(isbns[index++], "0-385-49532-3");
strcpy(isbns[index++], "0-321-19724-X"); // correct check digit is 0
strcpy(isbns[index++], "0-02-360692-4");
strcpy(isbns[index++], "0-321-19362-5"); // correct check digit is 8
strcpy(isbns[index++], "0-201-70433-1");
strcpy(isbns[index++], "1-56592-324-2"); // correct check digit is 3
strcpy(isbns[index++], "0-321-19498-5");
strcpy(isbns[index++], "0-13-034074-9"); // correct check digit is X
strcpy(isbns[index++], "0-13-790395-2");
strcpy(isbns[index++], "0-471-46983-0"); // correct check digit is 1
strcpy(isbns[index++], "0-670-82162-4");

for (int i=0; i<13; i++) {
ISBN isbn(isbns[i]);
isbn.print(cout);
if (isbn.valid())
cout << " is valid\n";
else cout << " is not valid\n";
}

ISBN isbn1("0", "670", "82162"),
isbn2("0", "13", "034074");
isbn1.print(cout); // should print "0-670-82162-4"
cout << endl;
isbn2.print(cout); // should print "0-13-034074-X"
cout << endl;
}

void check_book_class() {
Book texts[NUMBER_OF_BOOKS];
char title[81], author[81], isbn[14];
char publisher[8];
ifstream infile;
infile.open( "books.txt" );
if (!infile) {
cout << "Unable to open file books.txt\n";
return;
}
for (int i=0; i<NUMBER_OF_BOOKS; i++) {
infile.getline(title, 81);
cout << title << endl;
infile.getline(author, 81);
infile.getline(isbn, 14);
Book thisbook(title, author, isbn);
cout << "just read this book:\n";
thisbook.print(cout);
cout << endl;
texts[i] = thisbook;
}
cout << "Here are all of the books in the database\n\n";
for (int i=0; i<NUMBER_OF_BOOKS; i++) {
texts[i].print(cout);
cout << endl;
}
while (true) {
cout << "Enter a publisher code, or 'quit' to stop\n";
cin >> publisher;
if (strcmp(publisher, "quit") == 0) return;
cout << "Books by this publisher:\n\n";
for (int i=0; i<NUMBER_OF_BOOKS; i++)
if (strcmp(texts[i].getpublisher(), publisher) == 0) {
texts[i].print(cout);
cout << endl;
}
}
}

////////////////ISBN Class/////////////////////////////////////////////////////////

#include<iostream>
using namespace std;

class ISBN
{
public:
ISBN();
ISBN(char[ ]); // e.g., ISBN book("0-670-82162-4");
ISBN(char[ ], char[ ], char[ ], char); // 4-argument constructor is passed
// group code, publisher code, book
// code, and check character. e.g.
// ISBN book("0","670","82162","4");
ISBN(char[ ], char[ ], char[ ]); // 3-argument constructor is passed
// group code, publisher code, and
// book code. It computes the
// check character
// e.g. ISBN book("0","670","82162");
bool valid(); // true if check character is correct
char *getpublisher(); // return publisher code
void print(ostream &o); // print string with hyphens
int char_to_int(char c);

private:
char group[6]; // group code is 1-5 digits
char publisher[8]; // publisher code is 1-7 digits
char book[8]; // book code is 1-7 digits
char check;

int concat2[20];
char compute_check(); // compute the check character

};



ISBN::ISBN(char a[], char b[], char c[], char d)
{
strcpy(group, a);
strcpy(publisher, b);
strcpy(book, c);
check = d;
}

ISBN::ISBN(char a[], char b[], char c[])
{
strcpy(group, a);
strcpy(publisher, b);
strcpy(book, c);
check = compute_check();
}

ISBN::ISBN(char a[])
{
char deliminator[] = "-";
char check2[2];
strtok(a, deliminator);
strcpy(group, a);
strtok(NULL, deliminator);
strcpy(publisher, NULL);
strtok(NULL, deliminator);
strcpy(book, NULL);
strtok(NULL, deliminator);
strcpy(check2, NULL);
check = check2[0];
}

ISBN::ISBN(){}

char ISBN::compute_check()
{
char concat1[20];
strcat(concat1, group);
strcat(concat1, publisher);
strcat(concat1, book);
for (int i = 0; i <= 9; i++)
{
concat2[i] = char_to_int(concat1[i]);
}
int checkNumber = (concat2[0] * 1) + (concat2[1] * 2) + (concat2[2] * 3) + (concat2[3] * 4) + (concat2[4] * 5) + (concat2[5] * 6) + (concat2[6] * 7) + (concat2[7] * 8) + (concat2[8] * 9);
checkNumber = checkNumber % 11;
char checkChar = checkNumber;
if (checkNumber = 10)
checkChar = 'X';
return checkChar;
}

bool ISBN::valid()
{
char checkTest = compute_check();
return (checkTest = check);
}

char * ISBN::getpublisher()
{
return publisher;
}

void ISBN::print(ostream &o)
{
cout<<group<<"-"<<publisher<<"-"<<book<<"-"<<check<<endl;
}

//Function used to convert chars to int.

int ISBN::char_to_int(char c)
{
return c - '0';
}

///////////////////////BOOK CLASS///////////////////////////////////
#include <iostream>
#include "ISBN.h"
using namespace std;

class Book {
private:
char title[81]; // title no more than 80 characters
char author[51]; // author no more than 50 characters
ISBN isbn; // the book's ISBN

public:
Book();
Book(char[ ], char[ ], char[ ]); // e.g., ISBN book("The Odyssey",

// "Homer", "0-670-82162-4");
char *gettitle();
char *getauthor();
ISBN getisbn();
char *getpublisher(); // look up the publisher code
// in the isbn
void print(ostream &o); // print title, author, and isbn
};

Book::Book(char a[ ], char b[ ], char c[ ])
{
strcpy(title, a);
strcpy(author, b);
ISBN isbn(c);

}

Book::Book(){}

char * Book::gettitle()
{return title;}

char * Book::getauthor()
{return author;}

ISBN Book::getisbn()
{return isbn;}

char * Book::getpublisher()
{
return isbn.getpublisher();
}

void Book::print (ostream &o)
{
cout<<title<<", "<<author<<", "<<endl;
isbn.print(cout);
}
jpkirvan at 2007-11-9 0:56:48 >
# 3 Re: compiles but wont run
Well, its a fairly large program, Im trying to rearange it so that it will compile...
WHen I encounter problems like that, I do tons of couts to find out which area causes the error.Then I comment it out and try again.

Also, you should indent your code, and put comments on your closing brakets.
Makes your code more readable and it will be easier to find where one function ends and another begins.

Goodluck
mojo_jojo at 2007-11-9 0:57:50 >
# 4 Re: compiles but wont run
There ya go dude
http://www.agilman.org/crap/problem.cpp

I didn't solve it, but Im narrowing it down for ya

When you run main, it calls check_isbn_class()...
check_isbn_class runs a loop where it constantly generates objects type ISBN.
THe problem is somewhere in your ISBN class. Im about to start narrowing it down, tho Im kinda tired.

(ohh, and notice the indent style, makes code more readable)

Hope that helps ya.
mojo_jojo at 2007-11-9 0:58:53 >
# 5 Re: compiles but wont run
yeah i'll have to do it the old fashion way line by line cout statements
jpkirvan at 2007-11-9 0:59:50 >
# 6 Re: compiles but wont run
...or you could try a "new" way - run it under debugger.
You'll see that the crush is here:strcpy(publisher, NULL);
VladimirF at 2007-11-9 1:00:54 >
# 7 Re: compiles but wont run
You could try throwing away all your char arrays use strings and vectors of strings instead.
NMTop40 at 2007-11-9 1:01:58 >