문제가 말이죠...
문자열에 문장을 지정해주고
그 문장을 출력후 그 문장의 단어의 인덱스를 출력하는 거예요
단어는 사전순으로 정렬하는 거구로 단어 옆에 그 단어가 포함된 행을 숫자로 표현하는 거예요
그리고 단어를 입력 받아서 그 단어가 포함된 행을 전부 출력하는 거예요
저떤에는 하루죙일 해서 이렇게 짰는데 안돌아 가더라구요;;;;
더이상 어떻게 손봐야 될지도 모르겠구요..ㅠㅠ
부디부디 갈챠주세욤~ㅠㅠ
#include<stdio.h>
struct Date{
int line;
};
char *message[] = {"an empty street empty house",
" hold in side my heart",
" Alone room are getting smaller",
"I wonder why I wonder",
"I wonder where they are"};
char *word[5][5] = {"an", "empty", "street", "empty", "house",
"hold", "in", "side", "my", "heart",
"Alone", "room", "are", "getting", "smaller",
"I","wonder", "why", "I", "wonder",
"I", "wonder", "where", "they", "are"};
struct insertsort( char *[], int);
struct binarysearch( char *[], char);
int main()
{
int i,j;
char inkey2,message2[5];
for (i=0; i<5; i++){
printf ("%s\n", message[i]);
}
printf ("\n\n THs is a INDEX.");
for(j=0; j<25; j++){
inkey2 = message[i][j];
struct Data wordindex = binarysearch(char * word[], inkey2)
printf("%-20s %-5d\n", wordindex.word[j],wordindex,line[j]};
}
/* 이진검색으로 문자, 행 출력*/
printf("Enter a word:");
scanf("%s", &inkey[]);
if (inkey[] =!'#'){
message2[] = binarysearch( message, inkey);
strcp(message2[],message[]);
printf("%s\n", message2[line]);
}
/* 단어 입력 받아서 그 단어 포함된 줄 출력*/
else if
printf(" The test is over,Thank you^^");
/* '#' 입력되면 입력 중지*/
}
struct binarysearch(char *word2[], key) /* 이진검색*/
int left, right, mid;
left = 0;
right = 4;
mid = (left + right)/2;
while( left <= right){
for (i=0; i<5; ++i){
if(key == word2[i][mid]){
line = i+1;
}
else if (key > word2[i][mid])
left = mid + 1;
else
right = mid -1;
}
return(key,line);
}
struct insertsort (char *s[], int 25) /* 입력받은단어를 사전순으로 배열하는 함수*/
{
int i,j;
char *tmp;
for (i=1; i<25; i++){
tmp = s[i];
j = i-1;
while (j>=0 && strcmp(s[j].tmp)>0){
s[j+1] = s[j];
j--;
}
s[j+1] = tmp;
}
return(s[]);
}
|