C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 17th, 2013, 05:23 AM
asherman86 asherman86 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 6 asherman86 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 23 sec
Reputation Power: 0
Memory & arrays - Unhandled exception at 0x77b715de (ntdll.dll)

Hello everyone,

I am having a problem, and I pray some better programmers out there in internet land can help me with it. I am writing this project that uses multi-dimensional arrays and deals with file I/O to tab-delimited text files.

Up until now it was working FINE. It builds with no errors, compiles with no errors. And it was running perfectly fine. Now, all of a sudden, run it and I get a whole mess of errors.

It gets up to this point in my main function:
Code:
#include "datahandler.h"
#include "gradebook.h"
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdlib>
#include<cctype>
#include<string>
#include<vector>
#include<sstream>

using namespace std;

//FUNCTION PROTOTYPES
void displayMenu();


int main(){
	//create a local data-handler object to get a few preliminary
	//necessaries out of the way
	DataHandler dh;
	std::string classID;
	//create a 2D vector to hold all the class names so we can
	//deal with them individually:
	std::vector<std::vector<std::string>> vecClassNames;

	//fill the vector with all the information from Classes.txt
	dh.fillVector("Classes.txt", vecClassNames);

	//I've made this a const int since we won't be providing the user
	//the option to add any more classes than those that already exist in Classes.txt
	const int classCount = vecClassNames.size();

	//now we can create a vector of GradeBooks for each class:
	std::vector<GradeBook> gradeBooks (classCount);
	for(unsigned int i=0; i<gradeBooks.size(); i++){
		//since we KNOW that [i][0] holds the class ID, and [i][1] holds the Class Name
		//we can pass those valuse in order to the GradeBook constructor
		gradeBooks[i] = GradeBook(vecClassNames[i][0], vecClassNames[i][1]);
	}


Okay, fine up to there, then I walked on in to the GradeBook contructor:
Code:
GradeBook::GradeBook(std::string ID, std::string ClassName){
	//fill a vector with Student Informaiton for this particular gradebook
	std::string filename = "StudentInfo.txt";
	className = ClassName;
	classID = ID;

	//fill the vecStudents vector
	dh.fillVector(ID, filename, vecStudents);

	//fill a vector with assignment information for this particular gradebook
	filename = "Assignments.txt";
	dh.fillVector(ID, filename, vecClassAssignments);
	
	//fill a vector with student grade information for this particular gradebook
	filename = "StudentGrades.txt";
	dh.fillVector(filename, vecStudents, vecStudentGrades);
}


so, once it hits that point, it starts going haywire.
I get:
1. Unhandled exception at 0x77b715de (ntdll.dll) in StudentGradeBook.exe: Microsoft C++ exception: std:ut_of_range at memory location 0x0041f380..
with the options only to Break or Continue

If I click Continue I get:
2.Unhandled exception at 0x77b715de (ntdll.dll) in StudentGradeBook.exe: 0x00000000: The operation completed successfully.

...with the same options pretty much repeatedly.

I have absolutely no idea how to solve this problem. ANY help at all would ... well, it would help.

Also, this isn't a class assignment or anything, I'm just ... well, I was TRYING to help a friend who's taking a C++ class, and I thought I was doing pretty well up to this point, but I just can't fathom why all of a sudden it would stop working. I can code alright, but I don't understand all of the cryptic crap in these header files where all of these errors are occurring.

Reply With Quote
  #2  
Old February 17th, 2013, 07:19 PM
asherman86 asherman86 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 6 asherman86 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 23 sec
Reputation Power: 0
Narrowing it down

Okay, after spending hours upon hours breaking and walking through the code, I've found that the problem is NOT (I don't think) something to do with the code itself; I believe there is something wrong with the StudentInfo.txt file.

I don't know why but up to now this loop:
Code:
//move back to beginning of file to read
input.seekg(0, std::ios::beg);

//read one line into string row
for(std::string row; getline(input, row, row_delim); ){
     //add an item to the first dimension of vector rows
     rows.push_back(Rows::value_type());

     //feed the row into an input stringstream
     std::istringstream ss(row);

     //loop through the string and get each field
     for(std::string field; getline(ss, field, field_delim);){
          //add the field to the second dimension of the vector
          rows.back().push_back(field);
     }
     //assign the ID we need from that row to a test string
     std::string id = rows.back().at(IDindex);
     
     //if it isn't not the ID we're looking for, pop the entire
     //row off of the vector
     if (id != ID)
          rows.pop_back();
}


This loop always terminated upon reaching the end of the file. Now it just tries to keep going, as if it never reached the EOF, and when
row = "", it pushes back a blank, empty item onto the vector... then...

it gets to the line
Code:
std::string id = rows.back().at(IDindex)
which contains NOTHING... then...

ALL HELL BREAKS LOOSE.

Comments? Suggestions? Why isn't the loop terminating now like it used to? Is it even POSSIBLE to delete the end of file character? Do I have a blank line at the end of the file that I'm unaware of?

Let me jigger around with this... open to any suggestions.

Reply With Quote
  #3  
Old February 17th, 2013, 07:54 PM
asherman86 asherman86 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 6 asherman86 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 23 sec
Reputation Power: 0
Figgered It Out

HERE WAS THE PROBLEM:

In my data handler, I had a writeRecord method that was outputting a newline after writing the new record to the given file; that's why my fillVector method was reading a blank line! That's why it was throwing all kinds of ridiculous errors when it would try to assign std::string id NOTHING.

Soooo, I just had to remove ONE LINE of code from the writeRecord method and go back and fix my text file, and voila!! Problem solved.

The moral of this story is this:

If everything was working just fine up to a point then suddenly goes haywire, and you haven't really changed anything about the CODE itself, look to the I/O and the data. That's very possibly where your problem is.

Lesson learned and applied!

Reply With Quote
  #4  
Old February 21st, 2013, 03:24 AM
asherman86 asherman86 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 6 asherman86 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 23 sec
Reputation Power: 0
Sure, fire away!

Reply With Quote
  #5  
Old February 22nd, 2013, 01:30 AM
asherman86 asherman86 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 6 asherman86 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 23 sec
Reputation Power: 0
What?

Sorry but all I can see in y'all's posts are emoticons.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Memory & arrays - Unhandled exception at 0x77b715de (ntdll.dll)


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap