Computing.Net > Forums > Programming > Problem with a C++ program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Problem with a C++ program

Reply to Message Icon

Name: earthstation
Date: June 27, 2007 at 00:30:23 Pacific
OS: Win XP Home SP2
CPU/Ram: AMD Durion 1.07GHz/ 378MB
Product: Asus
Comment:

Hi,
I'm, hoping that someone can help me out with a problem i'm having. I'm making a program for management of small personal libraries. i recently ran into a bug while loading the program where it had to close. I'm not sure what exactly is causing the error so i was hoping someone could help me find and solve it. I think something in the function i'm using to load the library file (a text file) is causing it so here's the source for the function:
void loadLib()
{
//this function loads the library file into the global loadedLibrary array
ifstream openLibFile("library.txt");
int cellColumn, cellRow;

openLibFile.open();

if (! openLibFile)
{
cout << "\a !!Program Error!!" << endl;
cout << "Error Code: 426" << endl;
cout << "The program cannot find the library file!" << endl;
cout << "Please make sure the library file is in the application directory!" << endl;
cout << "If you require further assistance please contact the program" << endl;
cout << "developer at " << endl;
cout << "with the title \'Drake Error \', please include the error code above" << endl;
cout << "and a description of what you were doing before you received the error." << endl;
cout << "The program will start without a library file." << endl;
cout << "Press enter to continue.." << endl;
cin.get();
}
else
{
cout << "Loading library....." << endl;
while (! openLibFile.eof())
{
if (cellRow = 4)
{
getline(openLibFile, loadedLibrary[cellColumn][cellRow]);
lastColumn++;
cellColumn++;
cellRow = 0;
}
else
{
getline(openLibFile, loadedLibrary[cellColumn][cellRow++]);
; }
}
openLibFile.close();
}
}


Thanks in advance for your help
If you have any questions regarding this please ask.



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: June 27, 2007 at 01:14:27 Pacific
Reply:

You never told us the error you're getting.

I'm not sure if your complier will allow it (I don't think it's suppose to), but you have a semicolon by itself on line 38.

35 else
36 {
37 getline(openLibFile, loadedLibrary[cellColumn][cellRow++]);
38 ; }
39 }
40 openLibFile.close();


0

Response Number 2
Name: earthstation
Date: June 27, 2007 at 07:35:09 Pacific
Reply:

The error i'm getting is windows telling me that the program encountered an error and needs to close. unfortunately that's about as detailed as it gets.
Removing the semi-colon seemed to fix that problem. Thanks for your help, i've got a new problem though, now its not finding the library file and is displaying the library not found error message, when the library file is in the directory with it.


0

Response Number 3
Name: earthstation
Date: June 27, 2007 at 07:54:09 Pacific
Reply:

nevermind, fixed that problem, now it's quitting while loading the library file again. same error message as before.


0

Response Number 4
Name: Razor2.3
Date: June 27, 2007 at 12:15:33 Pacific
Reply:

In that case, my guess would be that your globally declared array "loadedLibrary[][]" is too small for the amount of data used.


0

Response Number 5
Name: earthstation
Date: June 27, 2007 at 13:36:06 Pacific
Reply:

hmm, could be, but i don't think so, the library.txt file i'm loading only has information for about 20 books, the array is 500 indices long. could it be that it's too long?


0

Related Posts

See More



Response Number 6
Name: Razor2.3
Date: June 27, 2007 at 15:01:53 Pacific
Reply:

Alright, alright. I'll take a closer look. (Read: Run it though my compiler.)

1: Neither cellColumn nor cellRow are initialized to 0.

2: I'm not sure of the version of fstream you're using, but mine forces me to declare the file to use in the open() statement. IE:
ifstream openLibFile;
openLibFile.open("library.txt");

3: if (cellRow = 4) should be if (cellRow == 4)

4: I'm not sure you can get away with two dimensional string arrays. You might need to make it a one dimensional array.

That's it for now.


0

Response Number 7
Name: Razor2.3
Date: June 28, 2007 at 21:05:12 Pacific
Reply:

Update to #4: It's not that you can can't use two dimensional string arrays. The problem is the string class overrides the [] operator. So, you'll probably end up with something that looks like this:
loadedLibrary[cellColumn][cellRow][0] = ...


0

Response Number 8
Name: earthstation
Date: July 4, 2007 at 23:37:19 Pacific
Reply:

So the string class is overriding essentially what is the
address of the cell? I'm not sure i completely understand


0

Response Number 9
Name: Razor2.3
Date: July 5, 2007 at 18:34:07 Pacific
Reply:

Yep. It overrides it, and points it to its own char[].


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Problem with a C++ program

problem in compiling c program www.computing.net/answers/programming/problem-in-compiling-c-program/7435.html

Help with a C Program / Newbie www.computing.net/answers/programming/help-with-a-c-program-newbie/8071.html

I'm having problem c++ programming www.computing.net/answers/programming/im-having-problem-c-programming/17450.html