#include<stdio.h>
# include <malloc.h>
# include <stdlib.h>
typedef char LinkedList;
typedef struct node
{
LinkedList data;
struct node *next;
};
int main(void)
{
int n=0;
LinkedList p,k;
k=(LinkedList)malloc(sizeof(struct node));
k->next=NULL;
while(n<5)
{
p=(LinkedList)malloc(sizeof(struct node));
p->data=2*n+1;
p->next=k->next;
k->next=p;
n++;
printf("%s ",p->data);
}
k->data=n;
return 0;
}
编译不过去,什么原因,请高手帮助?
你的定义有问题,应该改为:
typedef struct node* LinkedList;
typedef struct node
{
int data;
struct node *next;
};
printf("%s ",p->data);改为printf("%d ",p->data);
完整代码;
#include<stdio.h>程序无法运行
追答printf("%d ",p->data); 后面的修改了,就好了吧,呵呵,估计你开始看的是我前面的修改,后来改了