创建链表,编绎没错啊,内存不能writen,怎么回事?
程序代码:
#include "stdio.h" #include <stdlib.h> #include <malloc.h> #define LEN sizeof(struct list) typedef struct list { int data; struct list *next; }node; void main() { node* ptr,*head; int num,i; ptr=(node*)malloc(LEN); ptr=head; printf("input 5 numbers:\n"); for(i=0;i<5;i++) { scanf("%d",&num); ptr->data=num; ptr->next=(node*)malloc(LEN); if(i==4) ptr->next=NULL; else ptr=ptr->next; } free(ptr); ptr=head; while(ptr!=NULL) { printf("The value is==>%d\n",ptr->data); ptr=ptr->next; } }