卡片系统

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>

struct node *searchNode(int pos);

//结点声明
struct node
{
 //数据
 void *data;
 //链接
 struct node *next;
};

struct node *head=NULL;
struct node *pos=NULL;
int nodeCount=0;

struct card
{
 char name[20];
 char telephone[20];
 char address[20];
};

void insert(void *tdata)
{
 struct node *p;
 p=(struct node*)malloc(sizeof(struct node));
 if(p==NULL)
 {
  return;
 }
 p->data=tdata;
 p->next=NULL;
 if(head==NULL)
 {
  head=p;
  pos=p;
 }
 else
 {
  pos->next=p;
  pos=p;
 }
 nodeCount++;
}

int deleteAllNodes(void (*functionPtr)(void *))
{
 if(nodeCount==0)
 {
  return 0;
 }
 else
 {
  struct node *temp=NULL;
  while(head!=NULL)
  {
   temp=head;
   head=head->next;
   if(temp!=NULL)
   {
    functionPtr(temp->data);
    free(temp);
   }
  }
  nodeCount=0;
  pos=NULL;
  return 1;
 }
}

int deleteNode(void (*functionPtr_A)(void *),int (*functionPtr_B)(void *),int nodePos,void *data)
{
 if(nodePos==0)
 {
  return 0;
 }
 else
 {
  struct node *tempPtr;
  if(nodePos==-1)
  {
   int tempPos=functionPtr_B(data);
   if(tempPos==1)
   {
    tempPtr=head;
    head=head->next;
    if(tempPtr!=NULL)
    {
     //释放数据
     functionPtr_A(tempPtr->data);
     //释放结点
     free(tempPtr);
     nodeCount--;
     return 1;
    }
   }
   else
   {
    tempPtr=searchNode(tempPos-1);
    struct node *tempPtr_A;
    if(tempPos==nodeCount)
    {
     tempPtr_A=tempPtr->next;
     tempPtr->next=NULL;
     pos=tempPtr;
    
    }
    else
    {
     tempPtr_A=tempPtr->next;
     tempPtr->next=tempPtr->next->next;
    }
    //释放数据
    functionPtr_A(tempPtr_A->data);
    //释放结点
    free(tempPtr_A);
    nodeCount--;
    return 1;
   }

  }
  else
  {
   
   if(nodePos>=1)
   {
    if(nodePos==1)
    {
     tempPtr=head;
     head=head->next;
     if(tempPtr!=NULL)
     {
      //释放数据
      functionPtr_A(tempPtr->data);
      //释放结点
      free(tempPtr);
      nodeCount--;
      return 1;
     }
    }
    else
    {
     tempPtr=searchNode(nodePos-1);
     struct node *tempPtr_A;
     if(nodePos==nodeCount)
     {
      tempPtr_A=tempPtr->next;
      tempPtr->next=NULL;
      pos=tempPtr;
     
     }
     else
     {
      tempPtr_A=tempPtr->next;
      tempPtr->next=tempPtr->next->next;
     }
     //释放数据
     functionPtr_A(tempPtr_A->data);
     //释放结点
     free(tempPtr_A);
     nodeCount--;
     return 1;
    }
   }
  }

 }
}

int compareData(void *ptr)
{
 struct card *tempPtr_A=(struct card *)ptr;
 struct card *tempPtrData=NULL;
 struct node *tempPtr_B=NULL;
 if(head==NULL)
 {
  return 0;
 }
 for(int t=1;t<=nodeCount;t++)
 {
  tempPtr_B=searchNode(t);
  tempPtrData=(struct card *)tempPtr_B->data;
  if(strcmp(tempPtr_A->name,tempPtrData->name)==0)
  {
   return t;
  }

 }
}

void nodeEditor(void *tdata,void *newData,int (*functionPtr)(void *),void (*function_B)(void *))
{
 int pos=functionPtr(tdata);
 if(pos>=1)
 {
  struct node *tempPtr=searchNode(pos);
  function_B(tempPtr->data);
  tempPtr->data=newData;
 }
}

struct node *searchNode(int tpos)
{
 if(tpos==1)
 {
  return head;
 }
 if(tpos==nodeCount)
 {
  return pos;
 }
 struct node *ptr;
 ptr=head;
 for(int t=1;t<tpos;t++)
 {
  ptr=ptr->next;
 }
 if(ptr!=NULL)
 {
  return ptr;
 }
 else
 {
  return NULL;
 }
}

void deleteCard(void *ptr)
{
 if(ptr==NULL)
 {
  return;
 }
 struct card *tempPtr;
 tempPtr=(struct card *)ptr;
 if(tempPtr!=NULL)
 {
  free(tempPtr);
 }
}

void insertNewCard(char *tname,char *ttelephone,char *taddress)
{
 struct card *p=(struct card *)malloc(sizeof(struct card));
 strcpy(p->name,tname);
 strcpy(p->telephone,ttelephone);
 strcpy(p->address,taddress);
 insert(p);
}

void main()
{
 int chose=0;
 int temp_pos;
 struct card temp;
 char buf_1[20];
 char buf_2[20];
 char buf_3[20];
 char buf_4[20];
 while(1)
 {
 /* for(int t=0;t<20;t++)
  {
   buf_1[t]='/0';
   buf_2[t]='/0';
   buf_3[t]='/0';
   buf_4[t]='/0';
  }  */
  system("cls");
  printf("----------名片管理----------/n");
  printf("1.添加名片 /n");
  printf("2.名片修改 /n");
  printf("3.名片查询 /n");
  printf("4.名片删除 /n");
  printf("5.全部删除 /n");
  printf("6.打印全部名片 /n");
  printf("7.退出 /n");
  printf("----------------------------/n");
  printf("选择:");
  scanf("%d",&chose);
  switch(chose)
  {
  case 1:
   system("cls");
   printf("----------添加一个名片-----------/n");
   printf("姓名:");
   scanf("%s",buf_1);
   printf("电话:");
   scanf("%s",buf_2);
   printf("地址:");
   scanf("%s",buf_3);
   insertNewCard(buf_1,buf_2,buf_3);
   printf("---------------------------------/n");
   break;
  case 2:
   system("cls");
   printf("----------修改名片-------------/n");
   printf("输入已有名片的姓名:");
   scanf("%s",buf_4);
   strcpy(temp.name,buf_4);
   temp_pos=compareData(&temp);
   if(temp_pos>=1)
   {
    printf("已经找到数据,请修改...../n");
    printf("输入新的名字:");
    scanf("%s",buf_1);
    printf("输入新的电话:");
    scanf("%s",buf_2);
    printf("输入新的地址:");
    scanf("%s",buf_3);
    struct card temp_data;
    strcpy(temp_data.name,buf_1);
    strcpy(temp_data.telephone,buf_2);
    strcpy(temp_data.address,buf_3);
    nodeEditor(&temp,&temp_data,compareData,deleteCard);
    
   }
   else
   {
    printf("无法找到指定数据,请重新输入......./n");

   }
   printf("输入任意键继续...../n");
   _getch();
   break;
  case 3:
   system("cls");
   printf("-------------名片查询---------------/n");
   printf("输入姓名:");
   scanf("%s",buf_4);  
   strcpy(temp.name,buf_4);
   temp_pos=compareData(&temp);
   if(temp_pos>=1)
   {
    printf("已经找到数据,请修改...../n");
    struct node *temp_node=searchNode(temp_pos);
    struct card *ptr=(struct card *)temp_node->data;
    printf("------------------/n");
    printf("姓名: %s/n",ptr->name);`
    printf("电话: %s/n",ptr->telephone);
    printf("地址: %s/n",ptr->address);
    printf("------------------/n");
   }
   else
   {
    printf("无法找到指定数据,请重新输入......./n");
   }
   printf("输入任意键继续...../n");
   _getch();
   break;
  case 4:
   system("cls");
   printf("--------------名片删除----------------/n");
   printf("输入要删除名片的姓名:");
   scanf("%s",buf_4);
   strcpy(temp.name,buf_4);
   temp_pos=compareData(&temp);
   if(temp_pos>=1)
   {
    printf("已经找到数据,请删除...../n");
    if(deleteNode(deleteCard,compareData,-1,&temp)==1)
    {
              printf("Dlete Sucessfully!/n");
    }
   }
   else
   {
    printf("无法找到指定数据,请重新输入......./n");
   }
   printf("输入任意键继续...../n");
   _getch();
   break;
  case 5:
   system("cls");
   printf("--------------全部删除----------------/n");
   temp_pos=compareData(&temp);
   if(temp_pos>=1)
   {
    printf("已经找到数据,请删除...../n");
    deleteAllNodes(deleteCard);
    printf("Dlete Sucessfully!/n");
   }
   else
   {
    printf("无法找到指定数据,请重新输入......./n");
   }

   printf("输入任意键继续...../n");
   _getch();
   break;
   case 6:
   system("cls");
   printf("--------------打印全部名片----------------/n");
   temp_pos=compareData(&temp);
   if(temp_pos>=1)
   {
    printf("已经找到数据,请打印...../n");
    if(head==NULL)
    {
     return ;
    }
    for(int temp_pos=1;temp_pos<=nodeCount;temp_pos++)
    {
     struct node *temp_node=searchNode(temp_pos);
     struct card *ptr=(struct card *)temp_node->data;
     printf("------------------/n");
     printf("姓名: %s/n",ptr->name);
     printf("电话: %s/n",ptr->telephone);
     printf("地址: %s/n",ptr->address);
     printf("------------------/n");
    }
   }
   
   else
   {
    printf("无法找到指定数据......./n");
   }
   printf("输入任意键继续...../n");
   _getch();
   break; 
  
   


  case 7:
   system("cls");
   printf("释放内存空间............./n");
   deleteAllNodes(deleteCard);
   printf("成功释放....退出..../n");
   return;
   break;

  }
 }

}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值