免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2767 | 回复: 6
打印 上一主题 下一主题

[C] dereferencing pointer to incomplete type [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-11-14 12:02 |只看该作者 |倒序浏览

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4. #include <stdbool.h>    // For bool, false, true
  5. #include <string.h>     // For strcmp()

  6. struct Family * get_person(void);

  7. struct Famliy *pmember1;
  8. struct Family *pmember2;
  9. bool set_ancestry_fuck(struct Famliy *pmember1, struct Family *pmember2);



  10. struct Date
  11. {
  12.     int day;
  13.     int month;
  14.     int year;
  15. };


  16. struct Family
  17. {
  18.     struct Date dob;
  19.     char name[20];
  20.     char father[20];
  21.     char mother[20];
  22.     struct Family *next;            /* Pointer to next structure     */
  23.     struct Family *previous;        /* Pointer to previous structure */
  24.     struct Family *p_to_pa;         /* Pointer to father structure   */
  25.     struct Family *p_to_ma;         /* Pointer to mother structure   */
  26. };


  27. int main(void)
  28. {
  29.     struct Family * first   = NULL; /* Pointer to first person     */
  30.     struct Family * current = NULL; /* Pointer to current person   */
  31.     struct Family * last    = NULL; /* pointer to last person      */
  32.     char more = '\0';               /* Test value for ending input */
  33.     for ( ; ; ){
  34.         printf("\nDo you want to enter details of a%s person (Y or N)? ",
  35.                first != NULL ? "nother" : "");
  36.         scanf(" %c", &more);
  37.         if (tolower(more) == 'n')
  38.             break;
  39.         printf("\n");// 为了美观

  40.         current = get_person();

  41.         if (first == NULL){
  42.             first = current;    /* Set pointer to first Family */
  43.             last  = current;    /* Remember fot next iteration */
  44.         }
  45.         else{
  46.             last->next = current;       /* Set next address for previous Family */
  47.             current->previous = last;   /* Set previous address for current     */
  48.             last = current;             /* Remember for next iteration          */
  49.         }

  50.     }

  51.     /** Now tell them what we know **/

  52.     /** Ouput Family data in reverse order **/
  53.     while (current != NULL){
  54.         printf("\n");// 为了美观
  55.         printf("\n%s was born %d/%d/%d, and has %s and %s as parents.",
  56.         current->name, current->dob.day, current->dob.month,
  57.         current->dob.year, current->father, current->mother);
  58.         last = current;                 /* Svae pointer to enable memory to be freed */
  59.         current = current->previous;    /* current points to previous list           */
  60.         free(last);                     /* Free memory for the Family we output      */
  61.     }
  62.     printf("\n");// 为了美观

  63.     return 0;
  64. }



  65. /** Function to input data on Family members **/
  66. struct Family * get_person(void)
  67. {
  68.     struct Family * temp;

  69.     /* Allocate memory for a structure */
  70.     temp = (struct Family *)malloc(sizeof(struct Family));

  71.     printf("\nEnter the name of the person: ");                   /* Read the Family's name */
  72.     scanf("%s", temp -> name);

  73.     printf("\nEnter %s's date of birth (day month year): ", temp->name);
  74.     scanf("%d %d %d", &temp->dob.day, &temp->dob.month, &temp->dob.year);

  75.     printf("\nWho is %s's father? ", temp->name);
  76.     scanf("%s", temp -> father);    /* Get the father's name */

  77.     printf("\nWho is %s's mother? ", temp->name);
  78.     scanf("%s", temp -> mother);    /* Get the mother's name */

  79.     temp->next = temp->previous = NULL;// set pointers to NULL
  80.     temp->p_to_pa = temp->p_to_ma = NULL;// set pointer to NULL

  81.     printf("\n");//为了美观

  82.     return temp;
  83. }

  84. bool set_ancestry(struct Famliy *pmember1, struct Family *pmember2)
  85. {
  86.     if (strcmp(pmember1->father, pmember2->name) == 0){
  87.         //pmember1->p_to_fa = pmember2;
  88.         return true;
  89.     }
  90.     if (strcmp(pmember1->mather, pmember2->name) == 0){
  91.         //pmember1->p_to_ma = pmember2;
  92.         return true;
  93.     }
  94.     else
  95.         return false;
  96. }

复制代码

论坛徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46处女座
日期:2013-10-24 14:25:01酉鸡
日期:2014-04-07 11:54:15
2 [报告]
发表于 2012-11-14 12:45 |只看该作者
打中文, 描述问题, 谢谢.

论坛徽章:
14
巨蟹座
日期:2013-11-19 14:09:4615-16赛季CBA联赛之青岛
日期:2016-07-05 12:36:0515-16赛季CBA联赛之广东
日期:2016-06-29 11:45:542015亚冠之全北现代
日期:2015-07-22 08:09:472015年辞旧岁徽章
日期:2015-03-03 16:54:15巨蟹座
日期:2014-12-29 08:22:29射手座
日期:2014-12-05 08:20:39狮子座
日期:2014-11-05 12:33:52寅虎
日期:2014-08-13 09:01:31巳蛇
日期:2014-06-16 16:29:52技术图书徽章
日期:2014-04-15 08:44:01天蝎座
日期:2014-03-11 13:06:45
3 [报告]
发表于 2012-11-14 13:55 |只看该作者
虽然能猜到楼主想干什么,但这种行为本身是很恶劣的

你应该这么说:
如下代码,编译时某某行报错,错误提示为 dereferencing pointer to incomplete type,请问怎么改正?

然后别人才可以告诉你,Famliy 拼错了

论坛徽章:
14
巨蟹座
日期:2013-11-19 14:09:4615-16赛季CBA联赛之青岛
日期:2016-07-05 12:36:0515-16赛季CBA联赛之广东
日期:2016-06-29 11:45:542015亚冠之全北现代
日期:2015-07-22 08:09:472015年辞旧岁徽章
日期:2015-03-03 16:54:15巨蟹座
日期:2014-12-29 08:22:29射手座
日期:2014-12-05 08:20:39狮子座
日期:2014-11-05 12:33:52寅虎
日期:2014-08-13 09:01:31巳蛇
日期:2014-06-16 16:29:52技术图书徽章
日期:2014-04-15 08:44:01天蝎座
日期:2014-03-11 13:06:45
4 [报告]
发表于 2012-11-14 13:55 |只看该作者
虽然能猜到楼主想干什么,但这种行为本身是很恶劣的

你应该这么说:
如下代码,编译时某某行报错,错误提示为 dereferencing pointer to incomplete type,请问怎么改正?

然后别人才可以告诉你,Famliy 拼错了

论坛徽章:
0
5 [报告]
发表于 2012-11-14 14:46 |只看该作者
回复 2# linux_c_py_php


   

论坛徽章:
0
6 [报告]
发表于 2012-11-14 14:47 |只看该作者
一时心急 什么都没注意 下次不会了回复 4# bruceteen


   

论坛徽章:
0
7 [报告]
发表于 2012-11-14 14:51 |只看该作者
  版主删帖吧 我这个烂提问方式 回过头来看 确实很
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP