dict2.c

来自「linux网络编程实例程序 socket程序 适合初学者。」· C语言 代码 · 共 65 行

C
65
字号
/* dict2.c - initw, insertw, deletew, lookupw */#include <string.h>#define	MAXWORD	50		/* maximum length of a command or word	*/#define DICTSIZ 100		/* maximum number of entries in diction.*/char	dict[DICTSIZ][MAXWORD+1];/* storage for a dictionary of words	*/int	nwords = 0;		/* number of words in the dictionary	*//*------------------------------------------------------------------------ * initw - initialize the dictionary to contain no words at all *------------------------------------------------------------------------ */intinitw(){	nwords = 0;	return 1;}/*------------------------------------------------------------------------ * insertw - insert a word in the dictionary *------------------------------------------------------------------------ */intinsertw(char *word){	strcpy(dict[nwords], word);	nwords++;	return nwords;}/*------------------------------------------------------------------------ * deletew - delete a word from the dictionary *------------------------------------------------------------------------ */intdeletew(char *word){	int	i;	for (i=0 ; i<nwords ; i++)		if (strcmp(word, dict[i]) == 0) {			nwords--;			strcpy(dict[i], dict[nwords]);			return 1;		}	return 0;}/*------------------------------------------------------------------------ * lookupw - look up a word in the dictionary *------------------------------------------------------------------------ */intlookupw(char *word){	int	i;	for (i=0 ; i<nwords ; i++)		if (strcmp(word, dict[i]) == 0)			return 1;	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?