请教:为什么同一程序结果不同
为什么以下程序在Tc下执行正确,在VC6下却执行失败,
系统提示"该内存不能为只读"之类的错误
#include "stdio.h"
#include "stdlib.h"
typedef struct node
{
char data;
struct node *next;
}NODE;
void creat(NODE **head)
{
NODE *p,*q;
char ch;
p=NULL;
q=NULL;
while((ch=getchar())!='\n')
{
p=(NODE *)malloc(sizeof(NODE));
p->data=ch;
if(!(*head))
(*head)=p;
else
q->next=p;
q=p;
}
if(q) q->next=NULL;
}
void print(NODE *head)
{
NODE *p;
p=head;
while(p)
{
printf("%c",p->data);
p=p->next;
}
}
main()
{
NODE **head;
head=NULL;
creat(head);
print(*head);
getchar();
return 0;
}