成语大全网 - 汉语词典 - c编程词典(编程词典软件)

c编程词典(编程词典软件)

#include "stdio.h"

#include "string.h"

#define N_1 3

#define N_2 20

#define N_3 200

int i,j;

/**************************************/

int strccmp(char *str1,char *str2)

{

int len;

int len_1=strlen(str1);

int len_2=strlen(str2);

for(i=0;str1[i]!='\0';i++)

{

if(str1[i]>='A'&&str1[i]<='Z') { str1[i]+=32; }

}

for(i=0;str2[i]!='\0';i++)

{

if(str2[i]>='A'&&str2[i]<='Z') { str2[i]+=32; }

}

len=len_1>len_2?len_2:len_1;

for(i=0;i<len;i++)

{

if(str1[i]>str2[i]) { return 1; }

else if(str1[i]<str2[i]) { return -1; }

}

if((len_1!=len_2)&&(len_1>len_2)) { return 1; }

else if((len_1!=len_2)&&(len_1<len_2)) { return -1; }

else { return 0; }

}

/**************************************/

void sort(char words[][N_2],char comments[][N_3])

{

int i,j;

char temp_1[N_2];

char temp_2[N_3];

for(i=0;i<N_1;i++)

{

for(j=i+1;j<N_1;j++)

{

if(strccmp(words[i],words[j])==1)

{

strcpy(temp_1,words[i]);

strcpy(words[i],words[j]);

strcpy(words[j],temp_1);

strcpy(temp_2,comments[i]);

strcpy(comments[i],comments[j]);

strcpy(comments[j],temp_2);

}

}

}

}

/**************************************/

int search(char *key,char words[][N_2])

{

int bot=0;

int top=N_1-1;

int mid;

while(bot<=top)

{

mid=(bot+top)/2;

if(strccmp(words[mid], key)==1) { top=mid-1; }

else if(strccmp(words[mid], key)==-1) { bot=mid+1; }

else { return mid; }

}

return -1;

}

/**************************************/

void main()

{

int mark;

char key[N_2];

char words[N_1][N_2];

char comments[N_1][N_3];

int i,j,k;

int strccmp(char *str1,char *str2);

void sort(char words[][N_2],char comments[][N_3]);

int search(char *key,char words[][N_2]);

printf("DATA:\n");

for(i=0;i<N_1;i++)

{

printf("Please enter word %d:\t", i+1);

gets(words[i]);

printf("please enter word%d's comments:\t", i+1);

gets(comments[i]);

}

sort(words,comments);

do

{

printf("\nPlease enter key : ");

gets(key);

if(*key==NULL) { break; }

mark=search(key,words);

printf("Comment : ");

if(mark==-1)

{

printf("This word does not exist!\n\n@_@\n\n");

}

else

{

printf("%s\n\n^_^\n\n",comments[mark]);

}

}while(1);

}