Hi, i have a function in which it takes in an array, its length, and the length of the new array.
when i run it, the code stops working and aborts-so its not even telling me whats wrong and ive tried a few things to no avail.
Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
float* avgComparisonsArray(string wordArr[], int max, int num4){//takes parameter max number of letters in a word from the file.
float* final=NULL;
for(int i=0;i<max;i++){//looping through number of letters
string* temp=NULL;
int temp_point=0;//will, at the final, have the total number of words with ith letters in them
for(int j=0;j<num4;j++){//looping through number of words in list
if(wordArr[j].length() == i){
temp[temp_point]=wordArr[j];
temp_point++;
}
}
//SET ALL FOUND VARS
//take array and add
final[i]=avgComparisons(temp,temp_point);
}
return final;
}
|
i can verify that avgComparisons works fine with any other input when run.
when calling it in main im using:
1 2
|
float *avg_comps=avgComparisonsArray(words,max_length,numwords);
cout << "average comparisons-array " << avg_comps << endl;
|
words is a pointer to an array of words, max_length is the maximum number of letters in a word in 'words' and numwords is the number of words in 'words'.
it crashes before i see anything printed about 'average comparisons-array' so i dont even know whats happening. im using visual studio2010 express.
i basically just want to re-use the temp array...
any help is much appreciated, thanks.