단어장 배열 내용 삭제에 대해서 ㅠ.ㅜ
푸르
질문 제목 :
단어장 프로 그램입니다. input book 책 이렇게 입력하면 book과 책이라는 것이 입력되고4개 이상 저장이 되면 맨 처음 단어가 사라지게 됩니다.그리고 각 명령어에 맞추어 동작 하게끔 되어 있습니다..
여기서 안되는 부분은 딱 한군데 ㅡ_ㅡ;;;; delete 입니당... 제가 input book 책 과 input clock 시계 이렇게 입력 한 후에 delete book 이라고 치면 book이 사라져야 되는데요 이쪽에서 프로그램이 멈춰버립니다... ㅠ.ㅜ 헤매고 있어요 도와주세요
배열 안의 내용을 사라지게 할려고 하다 보니 그런거 같아요 ㅠ.ㅜ
사실 뒤쪽 배열들을 하나씩 땡기면 될거 같긴 한데 그게 또 잘 안되고요 앜 하나만 안되니깐 이거 답이 없네요
질문 내용 :
#includestdio.h
#includectype.h
#includestring.h
int main(void)
{
int i=0,j,index,k,h,g;
char com[10];
char word[10][2][20];
char put[]=input;
char serch[]=search;
char modi[]=modify;
char allprin[]=allprint;
char del[]=delete;
char exi[]=exit;
char *token;
char *token1;
char *token2;
char g[]= ;
while(1)
{
printf(INSERT COMMANDER(if you want exit the program insert exit)\n);
gets(com);
if(strcmp(com,exi)==0)
{
printf(exit the program\n);
return 0;
}
token=strtok(com,g);
token1=strtok(NULL,g);
token2=strtok(NULL,g);
if(strcmp(token,put)==0)
{
strcpy(word[i][0],token1);
strcpy(word[i][1],token2);
if(i=4)
{
strcpy(word[i-4][0],word[i][0]);
strcpy(word[i-4][1],word[i][1]);
}
i++;
}
else if(strcmp(token,serch)==0)
{
index=0;
for(j=0;ji;j++)
{
if(strcmp(word[index][0],token1)==0)
{
printf(meaning is %s\n,word[index][1]);
index++;
}
else printf(HERE IS NOT WORD WHAT YOU FIND);
}
}
else if(strcmp(com,modi)==0)
{
for(k=0;ki;k++)
{
index=0;
if(strcmp(token1,word[index][0])==0)
{
strcpy(word[index][1],token2);
printf(change word is %s %s\n,word[index][0],word[index][1]);
}
index++;
}
}
else if(strcmp(token,allprin)==0)
{
printf(PRINT ALL WORDS\n);
for(h=0;hi;h++)
{
printf(%s,word[h][0]);
printf(%s,word[h][1]);
printf(\n);
}
}
else if(strcmp(token,del)==0)
{
index=0;
for(g=0;gi;g++)
{
if(strcmp(token1,word[g][0])==0)
{
strcpy(word[index][0],NULL);
strcpy(word[index][1],NULL);
}
index++;
}
}
else
printf(COMMANDAR IS NOT CORRECT\n);
}
return 0;
}