C语言静态链表输出小问题?
本意是给有3个节点的静态链表输入100,200,300这3个数,然后在屏幕上输出出来,结果输入后得出的输出结果都是0,0,0,不知道输入环节错在什么地方,拜托大家赐教一下...
本意是给有3个节点的静态链表输入100,200,300这3个数,然后在屏幕上输出出来,结果输入后得出的
输出结果都是0,0,0,不知道输入环节错在什么地方,拜托大家赐教一下,谢谢,源程序如下:
#include <stdio.h>
#include <conio.h>
struct lianbiao
{
int n;
struct lianbiao *next;
}a, b, c;
void display(struct lianbiao *head)
{
struct lianbiao *p = NULL;
p = head;
while(p != NULL)
{
printf("%d\n", p -> n);
p = p -> next;
}
void main(void)
{
struct lianbiao *head = NULL, *p = NULL;
clrscr();
head = &a; a.next = &b; b.next = &c; c.next = NULL;
p = head;
while(p != NULL)
{
scanf("%d", p -> n);
p = p -> next;
}
display(head);
} 展开
输出结果都是0,0,0,不知道输入环节错在什么地方,拜托大家赐教一下,谢谢,源程序如下:
#include <stdio.h>
#include <conio.h>
struct lianbiao
{
int n;
struct lianbiao *next;
}a, b, c;
void display(struct lianbiao *head)
{
struct lianbiao *p = NULL;
p = head;
while(p != NULL)
{
printf("%d\n", p -> n);
p = p -> next;
}
void main(void)
{
struct lianbiao *head = NULL, *p = NULL;
clrscr();
head = &a; a.next = &b; b.next = &c; c.next = NULL;
p = head;
while(p != NULL)
{
scanf("%d", p -> n);
p = p -> next;
}
display(head);
} 展开
展开全部
楼主注意啦!!!!
你在用scanf函数输入一个整数的时候p->n前要加上一个求地址符&
scanf("%d", p -> n); 应该改成 scanf("%d", &(p -> n));
#include <stdio.h>
#include <conio.h>
struct lianbiao
{
int n;
struct lianbiao *next;
}a, b, c;
void display(struct lianbiao *head)
{
struct lianbiao *p = NULL;
p = head;
while(p != NULL)
{
printf("%d\n", p -> n);
p = p -> next;
}
}
void main(void)
{
struct lianbiao *head = NULL, *p = NULL;
//clrscr();
head = &a; a.next = &b; b.next = &c; c.next = NULL;
p = head;
while(p != NULL)
{
scanf("%d", &(p -> n));
p = p -> next;
}
display(head);
}
你在用scanf函数输入一个整数的时候p->n前要加上一个求地址符&
scanf("%d", p -> n); 应该改成 scanf("%d", &(p -> n));
#include <stdio.h>
#include <conio.h>
struct lianbiao
{
int n;
struct lianbiao *next;
}a, b, c;
void display(struct lianbiao *head)
{
struct lianbiao *p = NULL;
p = head;
while(p != NULL)
{
printf("%d\n", p -> n);
p = p -> next;
}
}
void main(void)
{
struct lianbiao *head = NULL, *p = NULL;
//clrscr();
head = &a; a.next = &b; b.next = &c; c.next = NULL;
p = head;
while(p != NULL)
{
scanf("%d", &(p -> n));
p = p -> next;
}
display(head);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询