를 손상되었습니다비주얼 스튜디오 - 변수 '임시'주위에 스택 내가 cstrings의 배열을 정렬 빠른 정렬 알고리즘에 대한 요소를 분할하는 기능을 작성했습니다
void partition(char words[][MAXWORDLEN + 1], int start, int end, int& partitionIndex) {
char pivot[MAXWORDLEN + 1]; //choose last element to be the pivot
strcpy(pivot, words[end]);
partitionIndex = start; //partition index is initalized to the first index
for (int i = start; i < end; ++i) { //iterate through the array
if (strcmp(words[i], words[end]) < 0) {
char temp[MAXWORDLEN];
strcpy(temp, words[i]); //swap the element with the element corresponding to the partition index
strcpy(words[i], words[partitionIndex]);
strcpy(words[partitionIndex], temp);
partitionIndex++;
}
}
cout << end << endl;
char temp[MAXWORDLEN + 1];
strcpy(temp, words[end]);
strcpy(words[end], words[partitionIndex]);
strcpy(words[partitionIndex], temp);
}
그러나 프로그램을 실행하면 런타임 검사 오류가 발생합니다. MAXWORDLENGTH는 6이며 배열의 모든 단어는 4-6 자 사이에 있습니다. 피벗 배열이 있기 때문에
char temp[MAXWORDLEN + 1];
이에
char temp[MAXWORDLEN];
: 그래서 변수 임시 인덱스 partitionIndex에서 말을
'\ 0'에 대한 임시 [MAXWORDLEN + 1]? – coderredoc
@coderredoc 그래, 그래서 나는 c 함수를 사용할 수있다. –
'if' 문 안에서도 똑같이 만든다. 그것이 내가 의미하는 바이다. '임시 [MAXWORDLEN +1]' – coderredoc