060.记录个人资料

简介: 060.记录个人资料
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
struct Family *get_person(void);    /* Prototype for input function */
char related(struct Family *pmember1, struct Family *pmember2);
char set_ancestry(struct Family *pmember1, struct Family *pmember2);
struct Date   
{
  int day;
  int month;
  int year;
};
struct Family                      /* Family structure declaration   */
{
  struct Date dob;
  char name[20];
  char father[20];
  char mother[20];
  struct Family *next;            /* Pointer to next structure      */
  struct Family *previous;        /* Pointer to previous structure  */
  struct Family *p_to_pa;         /* Pointer to father structure   */
  struct Family *p_to_ma;         /* Pointer to mother structure   */
};
void main()
{
  struct Family *first = NULL;    /* Pointer to first person        */
  struct Family *current = NULL;  /* Pointer to current person      */
  struct Family *last = NULL;     /* Pointer to previous person     */
  char more = '\0';               /* Test value for ending input    */
  for( ; ; )
  {
    printf("\nDo you want to enter details of a%s person (Y or N)? ", 
      first != NULL?"nother " : "" );
    scanf(" %c", &more);
    if(tolower(more) == 'n') 
      break;
    current = get_person();
    if(first == NULL)
    {
      first = current;            /* Set pointer to first Family    */
      last = current;             /* Remember for next iteration    */
    }
    else
    {
      last->next = current;  /* Set next address for previous Family */  
      current->previous = last; /* Set previous address for current */
      last = current;           /* Remember for next iteration */             
    }
  }
  current = first;
  while(current->next != NULL)  /* Check for relation for each person in    */
  {                       /* the list up to second to last            */
    int parents = 0;      /* Declare parent count local to this block */
    last = current->next; /* Get the pointer to the next              */
    while(last != NULL)   /* This loop tests current person           */
    {                     /* against all the remainder in the list    */
      if(related(current, last))         /* Found a parent ?          */
        if(++parents == 2)   /* Yes, update count and check it        */
          break;             /* Exit inner loop if both parents found */
        last = last->next;     /* Get the address of the next           */
    } 
    current = current->next;   /* Next in the list to check             */
  }
  /* Now tell them what we know */
  /* Output Family data in correct order */
  current = first;
  while (current != NULL)  /* Output Family data in correct order  */
  {
    printf("\n%s was born %d/%d/%d, and has %s and %s as parents.",
      current->name, current->dob.day, current->dob.month,
      current->dob. year, current->father,  current->mother);
    if(current->p_to_pa != NULL )
      printf("\n\t%s's birth date is %d/%d/%d  ",
      current->father, current->p_to_pa->dob.day,
      current->p_to_pa->dob.month, 
      current->p_to_pa->dob.year);
    if(current->p_to_ma != NULL)
      printf("and %s's birth date is %d/%d/%d.\n  ",
      current->mother, current->p_to_ma->dob.day,
      current->p_to_ma->dob.month, 
      current->p_to_ma->dob.year);
    current = current->next;  /* current points to next in list       */
  }
  /* Now free the memory */  
  current = first;
  while(current->next != NULL)
  {
    last = current;     /* Save pointer to enable memory to be freed */
    current = current->next; /* current points to next in list       */
    free(last);         /* Free memory for last                      */
  }
}
/*   Function to input data on Family members   */
struct Family *get_person(void)
{
  struct Family *temp;         /* Define temporary structure pointer */
  /* Allocate memory for a structure */
  temp = (struct Family*) malloc(sizeof(struct Family));
  printf("\nEnter the name of the person: ");
  scanf("%s", temp -> name );         /* Read the Family's name */
  printf("\nEnter %s's date of birth (day month year); ", temp->name);
  scanf("%d %d %d", &temp->dob.day, &temp->dob.month, &temp->dob.year);
  printf("\nWho is %s's father? ", temp->name );
  scanf("%s", temp->father );        /* Get the father's name */
  printf("\nWho is %s's mother? ", temp -> name );
  scanf("%s", temp -> mother );      /* Get the mother's name */
  temp->next = temp->previous = NULL; /* Set pointers to NULL */
  temp->p_to_pa = temp->p_to_ma = NULL;    /* Set pointers to NULL  */
  return temp;          /* Return address of Family structure */
}
char set_ancestry(struct Family *pmember1, struct Family *pmember2)
{
  if(strcmp(pmember1->father, pmember2->name) == 0)
  {
    pmember1->p_to_pa = pmember2;
    return 1;
  }
  if( strcmp(pmember1->mother, pmember2->name) == 0)
  {
    pmember1->p_to_ma = pmember2;
    return 1;
  }
  else
    return 0;
}
/* Fill in pointers for mother or father relationships */
char related (struct Family *pmember1, struct Family *pmember2)
{
  return set_ancestry(pmember1, pmember2) ||
    set_ancestry(pmember2, pmember1);
}
相关文章
|
6月前
分享:2秒快速查询40万手机号码归属地,批量手机号码归属地查询可以导出excel表格,WPS表格查询手机号码归属地怎么操作,批量手机号码归属地批量查询软件,批量号码查询按省份和城市分类,按运移动号码电信号码联通号码分类整理
本文介绍了如何批量快速查询手机号码归属地并进行分类。首先,通过提供的百度网盘或腾讯云盘链接下载免费查询软件。其次,开启软件,启用复制粘贴功能,直接粘贴号码列表并选择高速查询。软件能在极短时间内(如1.76秒内)完成40多万个号码的查询,结果包括归属地、运营商、邮箱和区号,且数据准确。之后,可直接导出数据至表格,若数据超过100万,可按省份、城市及运营商分类导出。文章还附带了操作动画演示,展示全程流畅的处理大量手机号码归属地查询的过程。
319 0
分享:2秒快速查询40万手机号码归属地,批量手机号码归属地查询可以导出excel表格,WPS表格查询手机号码归属地怎么操作,批量手机号码归属地批量查询软件,批量号码查询按省份和城市分类,按运移动号码电信号码联通号码分类整理
|
JavaScript 前端开发 搜索推荐
HTML+JS 实现手机号码归属地查询功能
HTML+JS 实现手机号码归属地查询功能
314 0
HTML+JS 实现手机号码归属地查询功能
公示公告信息弹窗提示(一天只弹一次)
公示公告信息弹窗提示(一天只弹一次)
227 0
公示公告信息弹窗提示(一天只弹一次)
|
存储 JavaScript
使用LocalStorage存储用户已填写的表单信息(意外刷新后自动填充)
使用LocalStorage存储用户已填写的表单信息(意外刷新后自动填充)
158 0
使用LocalStorage存储用户已填写的表单信息(意外刷新后自动填充)
|
开发工具
APP - 一键查询自己名下全部电话卡,防止信息被盗用
APP - 一键查询自己名下全部电话卡,防止信息被盗用
329 0
APP - 一键查询自己名下全部电话卡,防止信息被盗用
|
Web App开发 JavaScript 前端开发
赚点微信页面外快的一点记录
最近做了个移动页面的外包,写下来,页面布局感觉是比PC页面简单一点。 不像PC页面内容那么多,而且PC端的浏览器比较多,这边的话,我就考虑的比较少。 最后在页面写完后自己整理了两个小插件分别是弹出框zDialog和表单验证zValidate。
赚点微信页面外快的一点记录
|
Java 数据库 数据安全/隐私保护
JSP+Servlet培训班作业管理系统[4]–记录登录用户信息
本文目录 1. 本章任务 2. 点击登录后记录用户信息 3. 构造测试用户对象 4. 显示登录用户信息 5. 测试
246 0
JSP+Servlet培训班作业管理系统[4]–记录登录用户信息
|
文字识别 安全
还在对访客纸质记录?来看看最新的人证对比
访客人员安全管理与内部人员管理是许多场合安全管理的重点之一。长期以来,众多单位仍然采用简单的手工访客登记,这种访客管理方式已适应不了信息化的需要;传统手工来访登记因采用手工输入,所以信息真实性不能保证;访客人员素质不一、登记字体潦草,从而使登记信息在需要时无法确认;纸质保存易丢失、易损坏、查找困难,信息难以较长时间保存,因此已经不适应现代工作方式,也满足不了安全需求。