最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

c語言單詞本的新增、刪除、查詢按順序顯示功能

 更新時間:2021年12月10日 14:10:12   作者:starmultiple  
這篇文章主要介紹了c語言單詞本的新增、刪除、查詢按順序顯示功能,本文通過示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

c語言單詞本的新增,刪除,查詢,按順序顯示

#include<stdio.h>
#include<string.h>
#define SIZE 100
int addword(char p[][20], int n);
int findword(char p[][20], int n, char *f);
int delword(char p[][20], int n, char *f);
void display(char p[][20], int n);
void menu();
int main()
{
	char myword[100][20];
	char word[20];
	char choice;
	int count = 0;
	int pos = -1;
	do {
		menu();
		printf("Please input your choice:");
		scanf("%c", &choice);
		getchar();
		switch (choice)
		{
		   case '1':
			        count = addword(myword, count);
		   break;
		   case '2':
			   printf("Please input what you are looking for:");
			   gets(word);
			   pos = findword(myword, count, word);
			   if (pos != -1)
				   printf("It's the %d word\n", pos + 1);
			   break;
		   case '3':
			   printf("Please input what you want to delete:");
			   gets(word);
			   count = delword(myword, count, word);
			   break;
		   case '4':
			display(myword, count);
			break;
		   case '0':choice='0';break;
		   default:
			   printf("Error input,please input your choice again!\n");


		}
	} while (choice);
	return 0;
}
void menu( )
{
	printf("----------1.增加單詞------------\n");
	printf("----------2.查詢單詞------------\n");
	printf("----------3.刪除單詞------------\n");
	printf("----------4.顯示單詞------------\n");
	printf("-------------0.退出-------------\n");

	
}
int addword(char p[][20], int n)
{
	int i, j;
	char pos = -1;
	char flag = 'y';
	char tmp[20];
	while (flag == 'y' || flag == 'Y')
	{
		if (n == SIZE)
		{

			printf("Word list is full\n");
			break;

		}
		else
		{
			printf("Iput your word:");
			gets(tmp);
			pos = findword(p, n, tmp);
			if (pos != -1)
			{
				printf("the word exits!\n");
				break;
			}
			else
			{
				if (n)
				{
					for (i = 0;i < n && strcmp(tmp, p[i])>0;i++);
					for (j = n;j > i;j--)
						strcpy(p[j], p[j - 1]);
					strcpy(p[i], tmp);
					n++;
				}
				else
				{
					strcpy(p[0], tmp);
					n = 1;
				}
			}
			
		}


		printf("Another word?(y/n):");
		scanf("%c", &flag);
		getchar();
		
		
	}
	return n;
}
int findword(char p[][20], int n, char *f)
{
	int i;
	int pos = -1;
	for (i = 0;i < n;i++)
	{
		if (!strcmp(p[i], f))
		{
			pos = i;
			break;
		}
	}
	return pos;
}
int delword(char p[][20], int n, char *f)
{
	int i;
	int pos = -1;
		pos = findword(p, n, f);
	if (pos == -1)
		printf("It'not in myword list!\n");
	else
	{
		for (i = pos;i < n - 1;i++)
		{
			strcpy(p[i], p[i + 1]);

		}
		n = n - 1;
	}
	return n;
}


void display(char p[][20], int n)
{
	int i;
	if (n)
	{
		for (i = 0;i < n;i++)
			puts(p[i]);

	}
	else
		printf("There is no word in myword list!\n");
}

結(jié)果如下

如下

到此這篇關(guān)于c語言單詞本的新增,刪除,查詢,按順序顯示的文章就介紹到這了,更多相關(guān)c語言單詞本內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

伊川县| 永寿县| 焉耆| 石景山区| 西盟| 南木林县| 台山市| 香港| 沽源县| 北海市| 黎川县| 内黄县| 弥渡县| 宁安市| 尚义县| 政和县| 龙州县| 惠州市| 平阳县| 巫山县| 远安县| 图片| 洪泽县| 左云县| 三门县| 普陀区| 云林县| 天等县| 安乡县| 太康县| 北京市| 乡城县| 峡江县| 陇川县| 行唐县| 鄂伦春自治旗| 宁晋县| 南召县| 富锦市| 高唐县| 洞头县|