编译-大一狗遇到了一个问题,请大手帮忙看看!!!!

问题描述

大一狗遇到了一个问题,请大手帮忙看看!!!!
  1. #include
  2. #include
  3. #include
  4. struct Node
  5. {
  6. int num;
  7. char name[10];
  8. char sex;
  9. int phone_number;
  10. char addr[31];
  11. struct Node *pnext;
  12. struct Node *pfront;
  13. };
  14. struct Node * creat()
  15. {
  16. struct Node *head,*temp,*tail=0;
  17. int numtemp;
  18. printf("请输入编号姓名性别电话号码和住址,编号为0退出:n");
  19. scanf("%d",&numtemp);
  20. while(numtemp>0)
  21. {
  22. temp=(struct Node *)malloc(sizeof(struct Node));
  23. temp->num=numtemp;
  24. scanf("%s%c%d%s",temp->name,&temp->sex,&temp->phone_number,temp->addr);
  25. if(!head)
  26. {
  27. head=tail=temp;
  28. }
  29. else
  30. {
  31. tail->pnext=temp;
  32. temp->pfront=tail;
  33. tail=temp;
  34. }
  35. printf("请输入编号姓名性别电话号码和住址,编号为0退出n");
  36. scanf("%d",&numtemp);
  37. }
  38. return head;
  39. }
  40. void getin(struct Node *head)
  41. {
  42. struct Node *p;
  43. struct Node *temp=head;
  44. p=(struct Node *)malloc(sizeof(struct Node));
  45. printf("输入新添加联系人的编号姓名性别电话号码和住址");
  46. scanf("%d%s%c%d%s",&p->num,&p->name,&p->sex,&p->phone_number,&p->addr);
  47. while(temp->pnext!=NULL)
  48. {
  49. if((temp->num)>(p->num))
  50. {
  51. p->pfront=temp->pfront;
  52. temp->pfront->pnext=p;
  53. p->pnext=temp;
  54. temp->pfront=p;
  55. }
  56. else
  57. temp=temp->pnext;
  58. }
  59. if(p->pnext==NULL)
  60. {
  61. temp->pnext=p;
  62. p->pfront=temp;
  63. }
  64. }
  65. void put(struct Node * head)
  66. {
  67. struct Node *temp=head;
  68. while(temp->pnext!=NULL)
  69. {
  70. printf("%dt%st%ct%dt%st",temp->num,temp->name,temp->sex,temp->phone_number,temp->addr);
  71. temp=temp->pnext;
  72. printf("n");
  73. }
  74. printf("%dt%st%ct%dt%st",temp->num,temp->name,temp->sex,temp->phone_number,temp->addr);
  75. }
  76. struct Node * serch(struct Node *head,char *names)
  77. {
  78. while(head!=NULL)
  79. {
  80. if(strcmp(head->name,names)==0)
  81. return head;
  82. else
  83. head=head->pnext;
  84. }
  85. printf("没有找到相关联系人");
  86. return 0;
  87. }
  88. void dele(struct Node *head,char *names)
  89. {
  90. while(head!=NULL)
  91. {
  92. if(strcmp(head->name,names)==0)
  93. {
  94. head->pfront->pnext=head->pnext;
  95. head->pnext->pfront=head->pfront;
  96. free(head);
  97. break;
  98. }
  99. else
  100. head=head->pnext;
  101. }
  102. }
  103. int main()
  104. {
  105. struct Node *head;
  106. int n;
  107. char names[20];
  108. char names2[20];
  109. struct Node *p;
  110. printf("创建通讯录请输入1,插入输入2,删除输入3,输出输入4,查找输入5,退出输入0n");
  111. scanf("%d",&n);
  112. while(n!=0)
  113. {
  114. switch(n)
  115. {
  116. case 1:
  117. head=creat();
  118. break;
  119. case 2:
  120. getin(head);
  121. break;
  122. case 3:
  123. printf("请输入要删除的联系人姓名n");
  124. gets(names);
  125. dele(head,names);
  126. break;
  127. case 4:
  128. put(head);
  129. break;
  130. case 5:
  131. printf("请输入要查找联系人的姓名n");
  132. gets(names2);
  133. p=serch(head,names2);
  134. printf("%dt%st%ct%dt%s",p->num,p->name,p->sex,p->phone_number,p->addr);
  135. break;
  136. case 0:
  137. while(head!=NULL)
  138. {
  139. struct Node *p=head;
  140. head=head->pnext;
  141. free(p);
  142. }
  143. return 0;
  144. }
  145. }
  146. return 0;
  147. }

解决方案

代码太长了,直接说你遇到了什么问题吧。

解决方案二:

请输入编号姓名性别电话号码和住址,编号为0退出;
我输入了编号姓名性别,
程序就直接结束了,返回了一个乱七八糟的数

解决方案三:

解决方案四:

p=(struct Node *)malloc(sizeof(struct Node));
只看到你分配了一次内存,后面循环都没有再分配过

解决方案五:

你先调试下,估计是内存分配问题,你仔细看下,我长期用C++,对C不熟了。最后直接说你遇到的问题,你这样提问题,也不好解决

解决方案六:

scanf的时候,格式加空格试试。 scanf("%s %c %d %s", ...)
看到没,那个%d、%c、%d、%s之间加上空格。

时间: 2024-09-17 03:29:55

编译-大一狗遇到了一个问题,请大手帮忙看看!!!!的相关文章

sql-本人是新手,菜鸟一个,请大神帮忙

问题描述 本人是新手,菜鸟一个,请大神帮忙 现有两个表 用户表 USER (user_id 主键) (user_name ) 部门表 DELOPE (delope_id 主键)(user_id)(delope_name) 现在请查出名字叫'王五'的所在部门名字及所在部门的人数. 请用oracle和sqlserver分别写一下. 解决方案 表没建对吧,员工表跟部门表应该是多对一的关系吧. USER (user_id 主键) (user_name )(delope_id ) DELOPE (delo

请大神帮忙做一个matlab的三次样条插值程序,小弟是小白啊,谢过了!急急急

问题描述 请大神帮忙做一个matlab的三次样条插值程序,小弟是小白啊,谢过了!急急急 已知: X=[1 3 6 8 10 14 16 20 23] Y=[0.345 0.343 0.616 0.900 0.581 0.302 0.250 0.101 0.104] 求: X=[1 2 3 ...... 23]对应的Y值 解决方案 x=[1 3 6 8 10 14 16 20 23]; y=[0.345 0.343 0.616 0.900 0.581 0.302 0.250 0.101 0.104

请大神帮忙写一个简单的聚类算法程序,在线等……用matlab或者java实现

问题描述 请大神帮忙写一个简单的聚类算法程序,在线等--用matlab或者java实现 Step1:将N个数据,按照从小到大的顺序排序 d1.d2,.....dn:其中d1时最小值,dn是最大值 聚类判别阈值计算方法为: Step2:让每个数据都作为一个类,那么有 {d1},{d2},{d3},.....{dn} Step3:计算聚类中心 假设共有P个类,那么1<=k<=P,其中r代表每个类中数据的个数,同时计算相邻两个聚类中心之间的距离,如下 Step4:找出相邻两个聚类中心的最小值 Ste

gcc-GCC编译时 链接阶段未指定正确的库文件 请大神帮忙看下

问题描述 GCC编译时 链接阶段未指定正确的库文件 请大神帮忙看下 解决方案 头文件有正确包含么?函数名拼写正确么?没找到这个函数. 解决方案二: 你的函数库文件没有link,你需要编译的时候通过-L来指定对应的lib 解决方案三: 我在做linphone 然后就出现问题了

malloc-C语言Easyx的一个问题,请大神帮忙看看

问题描述 C语言Easyx的一个问题,请大神帮忙看看 不知道为什么不出东西.. struct img { int x; int y; IMAGE imggrass; struct img next; }; main() { struct img *p; p=(struct img)malloc(sizeof(struct img)); initgraph(640,480); loadimage(&p->imggrass, "resbmp_grass.bmp"); p-&g

sql-有关数据库查询的一个问题请大家帮帮忙谢谢!!

问题描述 有关数据库查询的一个问题请大家帮帮忙谢谢!! 写一个查询SQL 将 oal_tb_waybill 表中创建时间近三个月 statee字段为2或5的数据查询出来 该怎么写呢 用的是MySql数据库 解决方案 日期间隔返回月数http://dodomail.iteye.com/blog/883422 解决方案二: SELECT * FROM oal_tb_waybill WHERE created > DATE_SUB(NOW(),INTERVAL 3 MONTH) AND created

求大神解答-刚进公司,一个问题看了好久请大神帮忙看看。。。。

问题描述 刚进公司,一个问题看了好久请大神帮忙看看.... The type javax.servlet.http.HttpServletResponse cannot be resolved. It is indirectly referenced from required .class files WebContext.java /cofcoWeb_subStation/src/net/xinshi/web line 1 Java Problem 解决方案 先查看 所有的jar 是否完整,

有一个关于用C语言编写流量控制的问题,请大神帮忙~

问题描述 有一个关于用C语言编写流量控制的问题,请大神帮忙~ #include #include int main() { char str[31],temp[31]; //定义IP地址为32位的字符类型 int a,b,c,d; //定义IP地址的四个字节为a,b,c,d,并且均为整型的 printf("请输入IP地址"); while(gets(str) != NULL); { if(scanf(str,"%d.%d.%d.%d",&a,&b,&

struts2.0-我写了一个简单的struts2登录验证但是不能跳转,找了好久也不知道为什么,请大神帮忙看一下,先谢了

问题描述 我写了一个简单的struts2登录验证但是不能跳转,找了好久也不知道为什么,请大神帮忙看一下,先谢了 解决方案 SUBMITE提交呢? 解决方案二: 解决方案三: 调试下Action方法进入了吗?