读书人

这如何会出有关问题呢

发布时间: 2012-03-12 12:45:32 作者: rapoo

这怎么会出问题呢?

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);

读书人网 >C语言

热点推荐