首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

这如何会出有关问题呢

2012-03-12 
这怎么会出问题呢?C/C++ code#includestdio.h#includestdlib.hstruct node{int datastruct node *nex

这怎么会出问题呢?

C/C++ code
#include<stdio.h>#include<stdlib.h>struct node{    int data;    struct node *next;};struct node* creat(){    struct node *p,*q,*h;    int i,n;        printf("input the node you want creat:");    scanf("%d",&n);    h=(struct node*)malloc(sizeof(struct node));    h->data=n;    h->next=NULL;    q=h;    for(i=0;i<n;i++)    {        p=(struct node*)malloc(sizeof(struct node));        printf("input num[%d]:",i);        q->next=p;        scanf("%d",p->data);        p->next=NULL;        q=p;    }    return h;}void print(struct node *h){    struct node *p;    p=h->next;    while(p!=NULL)    {        printf("%c",p->data);        p=p->next;    }}main(){    struct node *head;    head=creat();    print(head);}


[解决办法]
scanf("%d",&p->data);
[解决办法]
修改这语句后就正常了

scanf("%d",&p->data); //需要加取地址符号
[解决办法]
结贴吧! (*^__^*) 嘻嘻……
[解决办法]
探讨
scanf("%d",&p->data);

热点排行