3 Replies - 505 Views - Last Post: 13 February 2010 - 12:58 PM Rate Topic: -----

#1 BrettT.h  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 29-January 10

access violation error?

Posted 13 February 2010 - 12:14 PM

Today I started to write a word search solving program, it was going well until I encountered this problem: My program runs fine until it tries to check to see if one element of an array is the same as an element in the other

void search(){
	wrdcounter = 0;
	for (int counter = 0; counter < height; counter++){
		for (int cntr = 0; cntr < width; cntr++){
			thispoint = ((counter-1)*height)+(cntr);
///it breaks here       if (wfield[counter][cntr] == word[wrdcounter]){



when I get to the last line of this code snippet, my program says that it is an access violation, and breaks the execution, why does it do this.

any help would be appreciated,

Brett

Is This A Good Question/Topic? 0
  • +

Replies To: access violation error?

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: access violation error?

Posted 13 February 2010 - 12:50 PM

My guess is that you are going out-of-bounds in your array. Could you just post the entire source code (if you don't mind)? That would be easier for us to figure out your problem.
Was This Post Helpful? 0
  • +
  • -

#3 BrettT.h  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 29-January 10

Re: access violation error?

Posted 13 February 2010 - 12:52 PM

void search(){
	wrdcounter = 0;
	for (int counter = 0; counter < height; counter++){
		for (int cntr = 0; cntr < width; cntr++){
			thispoint = ((counter-1)*height)+(cntr);
			if (wfield[counter][cntr] == word[wrdcounter]){
				if (thispoint = (lastpoint+1)){
					matchcheck[wrdcounter] = wfield[counter][cntr];
					wrdcounter++;
				}
				if (wrdcounter == 0){
					spoint = ((counter-1)*height)+(cntr);
					lastpoint = ((counter-1)*height)+(cntr);
					matchcheck[wrdcounter] = wfield[counter][cntr];
					wrdcounter++;
				}
			}
			if(wrdcounter == wlength){
				for (int cnr = 0; cnr < wlength; cnr++){
					if (matchcheck[cnr] == word[cnr]){
						continue;
					}
					else {
						cout << "Fatal Error : search failed.\n";
						break;
					}
				}
			}
		}
	}
}


Was This Post Helpful? 0
  • +
  • -

#4 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: access violation error?

Posted 13 February 2010 - 12:58 PM

word[wrdcounter]


I'm pretty sure that "wrdcounter" increases over "word" total size.
I'd just put a condition here:
if ((wfield[counter][cntr] == word[wrdcounter]) && (wrdcounter < whatever_word_size_is))


This will assure that "wrdcounter" is not incremented over "word" size.
EDIT: be sure that you did not index "word" elements starting from 1.

This post has been edited by sarmanu: 13 February 2010 - 01:03 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1