将a、b、c三个结点链成一个单向链表,并给各结点的数据

将a、b、c三个结点链成一个单向链表,并给各结点的数据域赋值,函数fun的作用是:累加链表结点数据域中的数据作为函数值返回。

请改正程序中的错误,使它能得出正确的结果。

#include <stdio.h>
#include <stdlib.h>
typedef struct list
{
	int data;
	struct list *next;
} LIST;
int fun(LIST *h)
{
	LIST *p;
	int t=0;
	p=h;
	/**********found**********/
	while(*p)
	{
		/**********found**********/
		t=t+p.data;
		p=(*p).next;
	}
	return  t;
}
main()
{
	LIST a,b,c,*h; 
	a.data=34;
	b.data=51;
	c.data=87;
	c.next='\0';
	h=&a;
	a.next=&b;
	b.next=&c;
	printf("总和 = %d\n",fun(h));
	system("pause");
}


答案
第1空:while(p) / while(p!=NULL)
第2空:t=t+(*p).data; / t=t+p->data;

题目信息

题号:6695
题型:填空题
知识点:计算机二级
难度:普通