欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C++之預(yù)處理功能詳解

    C++之預(yù)處理功能詳解

    預(yù)處理器是 C++ 編譯器提供的一個(gè)工具,允許程序員在編譯之前對(duì)源代碼文件做出修改,本文將給大家通過代碼示例詳細(xì)介紹C++的預(yù)處理功能,需要的朋友可以參考下
    2023-05-05
  • C++中求組合數(shù)的各種方法總結(jié)詳解

    C++中求組合數(shù)的各種方法總結(jié)詳解

    本篇文章是對(duì)C++中的求組合數(shù)的各種方法進(jìn)行了詳細(xì)的介紹。需要的朋友參考下
    2013-05-05
  • C++取得當(dāng)前時(shí)間的方法

    C++取得當(dāng)前時(shí)間的方法

    這篇文章主要介紹了C++取得當(dāng)前時(shí)間的方法,實(shí)例展示了通過系統(tǒng)函數(shù)獲取當(dāng)前時(shí)間的實(shí)現(xiàn)方法,非常簡(jiǎn)單易懂,需要的朋友可以參考下
    2014-10-10
  • C++Zip壓縮解壓縮示例(支持遞歸壓縮)

    C++Zip壓縮解壓縮示例(支持遞歸壓縮)

    C++Zip壓縮解壓縮示例,用第三方函數(shù)封裝而成,支持 UNCODE, ANSCII、支持壓縮文件夾、支持遞歸壓縮
    2013-11-11
  • C++中ctemplate的使用

    C++中ctemplate的使用

    CTemplate是一種簡(jiǎn)單但功能強(qiáng)大的模板引擎,廣泛用于各種HTML模板解析和生成,本文主要介紹了C++中ctemplate的使用,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-01-01
  • 4組C語言中順序讀寫文件的函數(shù)分享

    4組C語言中順序讀寫文件的函數(shù)分享

    這篇文章主要為大家詳細(xì)介紹了4組C語言中實(shí)現(xiàn)順序讀寫文件的函數(shù),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-03-03
  • C++標(biāo)準(zhǔn)模板庫(kù)vector的常用操作

    C++標(biāo)準(zhǔn)模板庫(kù)vector的常用操作

    今天小編就為大家分享一篇關(guān)于C++標(biāo)準(zhǔn)模板庫(kù)vector的常用操作,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • C++中拷貝構(gòu)造函數(shù)的使用

    C++中拷貝構(gòu)造函數(shù)的使用

    大家好,本篇文章主要講的是C++中拷貝構(gòu)造函數(shù)的使用,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下
    2022-02-02
  • Matlab實(shí)現(xiàn)繪制立體玫瑰花的示例代碼

    Matlab實(shí)現(xiàn)繪制立體玫瑰花的示例代碼

    這篇文章主要介紹了如何利用Matlab實(shí)現(xiàn)繪制更立體的玫瑰花,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Matlab有一定的幫助,需要的可以參考一下
    2023-02-02
  • C++無痛實(shí)現(xiàn)日期類的示例代碼

    C++無痛實(shí)現(xiàn)日期類的示例代碼

    凡是要寫類必須要提到六大默認(rèn)成員(六位大爺):構(gòu)造函數(shù)、析構(gòu)函數(shù)、拷貝構(gòu)造函數(shù)、賦值重載函數(shù)、取地址重載函數(shù)(包括const對(duì)象和普通對(duì)象);那么這次的日期類又需要伺候哪幾位大爺呢?本文就來詳細(xì)說說
    2022-10-10

最新評(píng)論