程序出错,之显示第一个字符
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
char data;
struct node* next;
}listnode;
typedef struct node* linklist;
linklist createlist(void);
void insertlist(linklist,char,int);
void dellist(linklist,int);
linklist createlist(void){
linklist p;
linklist head,rear;
head=NULL;
rear=NULL;
char ch;
while((ch=getchar())!='\n'){
p=(linklist)malloc(sizeof(listnode));
p->data=ch;
if(head==NULL)
head=p;
else
rear->next=p;
rear=p;
if(rear!=NULL)
rear->next=NULL;
}
return head;
}
void insertlist(linklist head,char data,int i){
linklist s,p=head;
int j=0;
while(p!=NULL && j<i-1){
p=p->next;
j++;
}
if(p==NULL || j>i)
exit(1);
s=(linklist)malloc(sizeof(listnode));
s->data=data;
s->next=p->next;
p->next=s;
}
void dellist(linklist head,int i){
linklist p=head,r;
int j=0;
while(p!=NULL && j<i-1){
p=p->next;
j++;
}
r=p->next;
p->next=r->next;
free(r);
}
int main(void){
linklist newlist=createlist();
insertlist(newlist,"ZX",3);
dellist(newlist,4);
while(newlist!=NULL){
printf("%c",newlist->data);
newlist=newlist->next;
return 0;
}
}
只能显示出第一个字符,例如输入abcdfg,只能显示a