#include <stdio.h>
#include <string.h>
typedef struct dictionary
{
char str[1000][25];
size_t size;
}dictionary;
void DictionaryInt(dictionary* dic)
{
dic->size=0;
}
int DictinaryCheck(dictionary* dic,const char* keyword)//查“字典”
{
int i;
for ( i = 0; i < dic->size; i++)
{
if (strcmp(keyword,dic->str[i])==0)
{
return 0;
}
}
return 1;
}
void DictinaryAdd(dictionary* dic,const char* keyword)//添加“新词”
{
strcpy(dic->str[dic->size],keyword);
dic->size++;
}
int main(){
int cot;
char str[25];
dictionary dic;
dic.size=0;
while (scanf("%s",&str)!=EOF)
{
if (strcmp(str,"#")==0)
{
break;
}
if (DictinaryCheck(&dic,str))
{
DictinaryAdd(&dic,str);
}
if (getchar()=='\n')
{
printf("%d\n",dic.size);
DictionaryInt(&dic);
continue;
}
}
return 0;
}
利用好string.h中的库函数以及字符串数组,是可以实现c中的字典的(待续)