帮忙改一下程序!
这程序编译能通过但执行时有异常,单步执行时第二次循环有异常!#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
char c;
struct node *next;
}L;
int main()
{
L *l,*p,*q;
char ch;
l=(L*)malloc(sizeof(L));
l->c='\0';//'0','/0'
l->next=0;
q=l;
printf("input a charcter:\n");
scanf("%c",&ch);
getchar();
while(ch!='!')
{
p=(L*)malloc(sizeof(L));
p->c=ch;
p->next=0;
q->next=p;
q=p;
scanf("%c",ch);
getchar();
//p=0;
}
q=l;
while(q->next!=0)
{
printf("%c",q->next->c);
q=q->next;
}
}