Hi everybody, i want to compare between 2 vector that stored char value.
I've made 2 vector:

vector <char*> className;
vector <vector<char*> > Item;

first i stored the class data in each vector, the name of class in vector className. after that i get data from the other file that contain many values in Item. Item is 2D vector, it stored raw and column. the last column contain the value of class which i had stored in className

So i want to compare the value of the last column of each Item with the value of className, so i made this code:

vector <int> ClassFreq;
int p = numberOfAttribute+1; //this refer to the last column
int itemSize = (int)Item.size();
for(int i = 0; i < itemSize; i++)
	int nitemSize = (int)Item[i].size();
	for(int j=0; j < numberOfClass; j++)
		[B]if(strcmp(Item[i][p], namaKelas[j]))[/B]
			ClassFreq[j]++; //count the frequency of each class and store it in this vector

but it gave me an error message :
18 [main] c45 3296 handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
71292 [main] c45 3296 open_stackdumpfile: Dumping stack trace to c45.exe.stackdump

i really need help here, thank you so much...

Edited by sasTReSS: n/a

8 Years
Discussion Span
Last Post by sasTReSS

You never tell it how big ClassFreq should be, then you start accessing elements! It looks like you should do

vector <int> ClassFreq(numberOfClass);

but I'm still not exactly sure what you are trying to do, it seems like there may be a better way using stl functions.



Thank you Dave, i've realized that i forgot to give the value to the vector, so i changed it to an array:

int ClassFreq[MAXCLASS];

i've just realized my mistake (actually my friend told me), when i called this:

if((strcmp(Item[i][p], namaKelas[j]) )== 0 )

it's never true (or never print "printf("stress!");" because the length between Item and namaKelas is different so they're referring to different pointer.
when i do this:

printf("%d", *(namaKelas[j]));
printf("%d", *(Item[i][p]));

the result is different thus: 75 and 32. It was because the length between char in namaKelas and Item was different, char in item include space (exdample :' K') and the value of char in namaKelas just 'K', so they had different length and never will enter this:

if((strcmp(Item[i][p], namaKelas[j]) )== 0 )

Btw, thank you for your suggestion:

but I'm still not exactly sure what you are trying to do, it seems like there may be a better way using stl functions.

I'm new in this c++ thing, so i don't know all of the function in STL :)

Edited by sasTReSS: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.