Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5423
Number of posts: 16952

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Issue with User Input Posted by kayakinack on 10 May 2012 at 3:14 PM
When I call the following section of code, I get to the section to enter an integer for enter number of grades to drop and my program crashes.

void Course::enterGCInfo(int num)
{
	GradeCat tempGC;
	string tempStr = "";
	cout << "Enter Grade Category Name: ";
	cin >> tempStr;
	tempGC.setGCName(tempStr);
	double tempDbl = 0.0;
	cout << "Enter Grade Percentage: ";
	cin >> tempDbl;
	tempGC.setGCPerc(tempDbl);
	int tempInt = 0;
	cout << "Enter Number of Grades To Drop: ";
	cin >> tempInt;
	tempGC.setNumToDrop(tempInt);
	setGradeCat(num,tempGC);
	refresh();
}


This is the error message:
Unhandled exception at 0x004149eb in Grade Tracker.exe: 0xC0000005: Access violation reading location 0x3343f1c8.


I'm using Visual Studio 2010 Express - Start Debugging. When it reaches this error it takes me to following code in file xstring

	bool _Grow(size_type _Newsize,
		bool _Trim = false)
		{	// ensure buffer is big enough, trim to size if _Trim is true
		if (max_size() < _Newsize)
			_Xlen();	// result too long
		if (this->_Myres < _Newsize)
			_Copy(_Newsize, this->_Mysize);	// reallocate to grow
		else if (_Trim && _Newsize < this->_BUF_SIZE)
			_Tidy(true,	// copy and deallocate if trimming to small string
				_Newsize < this->_Mysize ? _Newsize : this->_Mysize);
		else if (_Newsize == 0)
			_Eos(0);	// new size is zero, just null terminate
		return (0 < _Newsize);	// return true only if more work to do
		}


The cursor stops next to this line:
if (this->_Myres < _Newsize)


The function calls dealing with that Integer input

setNumToDrop
void GradeCat::setNumToDrop(int num)
{
	numToDrop = num;
}


setGradeCat
void Course::setGradeCat(int num,GradeCat tempGC)
{
	GCs[num] = tempGC;
}


GCs is an array of GradeCat objects

refresh
void Course::refresh()
{
	calcGrade();
	calcTotalPerc();
	sortGradeCats();
}

Report
Re: Issue with User Input Posted by ciomalau on 11 May 2012 at 3:49 AM
why all = faknob? i want know! :(
Report
Re: Issue with User Input Posted by kayakinack on 10 May 2012 at 10:38 PM
umm, you'll have to put that into so easier language to me to understand.

Anyway, I figured out my problem, I knew it would be something stupid. I was not sending a proper value to the function, so that improper value was being used to insert an object into an array. DOH!
Report
Re: Issue with User Input Posted by ciomalau on 11 May 2012 at 8:58 AM
i see how they = st00pid but they all die... :(

man listen i want to start creating my own games in C++ using directx9. but i'm right at the start! i'm barely at chapter 4 from Thinking in C++. and i have some questions about what i learned. so take this as an example

void (*funcptr)();
//so this is a pointer to a function which takes no arguments and returns void

void* funcptr2();
//a function which returns a pointer to void

void* (*(*fp1)(int))[10];
//fp1 is a pointer to a function which takes an int an returns a pointer to an array of 10 pointers to void

float (*(*fp2)(int,int,float))(int);
//fp2 is a pointer to a function which takes 3 arguments and returns a pointer to a function which takes an int and returns float

i can read most of these expressions using the middle-right-left-right-etc method described in the book. but i'm not sure i can use this stuff - it seems too complicated. so if i take up game programming would i bump often into such things?

PS i now mother not home but she come late ok?



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.