quick sort관련 질문입니다.
큰말
질문 제목 : quick sort 관련 질문입니다.
입력한 단어를 피벗으로 설정하여 quick sort를 하는 소스입니다.
질문 내용 :
#include stdio.h
#include stdlib.h
#include string.h
#define max 200
void sort(char **keycode, char* serchkey,int first, int last);
int partition(char **keycode,char* serchkey, int first, int last);
int main(){
int i = 0,j;
int line = 0;
int serchnum = 0;
char** keycode;
char* serchkey;
file * file = fopen(hw2-data.txt, rt); // 파일을 엽니다.
if(file == null) // 이상이 있는지 체크합니다.
{
printf(파일을 못 읽었습니다.!\n);
return 0; // 종료
}
keycode = (char**)malloc(sizeof(char*)*max); //힙 영역에 저장하기 위해 keycode를 동적으로 할당합니다.
for( j=0; jmax; j++ ){
keycode[j] = (char*) malloc(sizeof( char )*50);
} while(1) // 반복문을 시작합니다.
{
if(feof(file) != 0) // 파일을 끝까지 읽었는지 확인을 합니다.
break;
fgets(keycode[i], max, file); //keycode에 파일에서 읽어온 값들을 저장합니다.
// *(keycode[i]+(strlen(keycode[i]) - 1))=0;
printf(%s,keycode[i]);
i++;
line++;
}
printf(pivot이 될 문자열을 입력하여 주세요:);
scanf(%s,&serchkey);
serchnum = partition(keycode,serchkey,0,line-1);
printf(%s는 %d번째 위치에 있습니다.\n,serchkey,serchnum);
sort(keycode,serchkey,0,line-1);
return 0;
}
void sort(char **keycode, char* serchkey,int first, int last){
int pivot;
if(firstlast){
pivot = partition(keycode,serchkey,first,last);
sort(keycode,serchkey,first,pivot-1);
sort(keycode,serchkey,pivot+1,last);
}
}
int partition(char **keycode,char* serchkey, int first, int last){
char* temp;
int i,j;
i=first-1;
for(j=first; jlast; j++){
if(strcmp(keycode[j],serchkey)=0){
i++;
if(i != j) {
temp = keycode[i];
keycode[i] = keycode[j];
keycode[j] = temp;
}
}
}
serchkey = keycode[i + 1];
keycode[i+1] = keycode[last];
keycode[last] = serchkey;
return i+1;
}
--------------------------
입력한 문자열을 피벗으로 하여 불러들인 파일을 퀵소트 하는 소스입니다.
patition.exe의 0x5052d442 (msvcr100d.dll)에 처리되지 않은 예외가 있습니다. 0xc0000005: 0xcc006f6e 위치를 읽는 동안 액세스 위반이 발생했습니다.
검색할 단어를 입력하면 위와같은 메세지가 나오면서 진행이 되질 않는데요.
무엇이 문제인지 도저히 모르겠내요...