⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 智能化查询过程c语言源代码.txt

📁 c语言的一些常见的算法以及思考和改进的文章,写的很不错,花费了很大的精力从网络了搜罗的,希望大家喜欢.
💻 TXT
字号:
智能化查询过程C语言源代码[原创] 
       说智能化,有点不太合适。程序用来查询用户输入的信息,如果查到,则输出;若没有查到,则向用户询问,且具有记忆和自动更新数据库功能。不足之处在于,没有实现模糊查询(利用字符串匹配的知识不难自行增加相应功能);没有实现删除错误信息的功能,以后有时间慢慢添加吧。暂时可以看作一个对文件操作的小程序。

#i nclude <stdio.h>
#i nclude <stdlib.h>
#i nclude <io.h>

void main()
{
   FILE *fp;
   char name[9]="",nameT[9]="",phone[9]="";
   char yn;     /*continue or not*/
   int yesno=1; /*continue to cycle or not*/
   int flag;  /*found or not*/
   fpos_t *pos;
   while(yesno)
   {
      fp=fopen("bugeyes.dic","r");
      if(fp==NULL)
      {
            printf("\nSorry.Something is wrong.I can not find my database.");
            exit(-1);
      }
      flag=0;
      printf("\nPlease input the name you want to search:");
      scanf("%s",nameT);
      while(!feof(fp))
      {
          fscanf(fp,"\n%s %s",name,phone);
          if(strcmp(name,nameT)==0)
          {
                 printf("\nOK.I have got it.\n");
                 printf("The phone of %s is %s",name,phone);
                 flag=1;
          }
      }
      if(flag!=1)
      {
            printf("\nSorry.I donnot know the answer.Can you tell me?(y/n)");
            scanf("%c",&yn);
            while(yn!='y'&&yn!='Y'&&yn!='n'&&yn!='N')
            {
                printf("\nCan you tell me?(y/n)");
                scanf("%c",&yn);
            }
            if(yn=='n'||yn=='N')
            {
               printf("\nSorry.I am very gret to hear that.Bye\n");
               fclose(fp);
               exit(-1);
            }
           else if(yn=='y'||yn=='Y')
           {
               printf("\nVery good!What is it?\n");
               scanf("%s",phone);
               fclose(fp);
               fp=fopen("bugeyes.dic","a");
               if(fp==NULL)
               {
                   printf("\nOpen database error.Sorry\n");
                   exit(-1);
               }
               fprintf(fp,"\n%s %s",nameT,phone);
               printf("\nThank you very much.I haver rememberd it\n");
               fclose(fp);
           }
      }
      scanf("%c",&yn);
      while(yn!='n'&&yn!='N'&&yn!='y'&&yn!='Y')
      {
           printf("\nDo you want to search another one?(y/n)");
           scanf("%c",&yn);
      }
      if(yn=='N'||yn=='n')
           yesno=0;
   }
}
 

⌨️ 快捷键说明

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