把输入的一串字符转成数组,转成链表,然后删去其中指定的字符,在尾部添加一个字符。 (程序还不完善,没有对输错的情况进行处理,,暂时先这样吧。。= =。) #include<stdio.h> #include<malloc.h> #define LEN sizeof(struct link) struct link { char ch; struct link *next; }*string; char a[80]={0}; void array() { scanf("%s",a); } void creat(char *a) { int i; struct link *head,*p; p=head=(struct link *)malloc(LEN); for(i=0;i<80;i++) { if(*(a+i)!=0) { p->ch=*(a+i); p->next=(struct link *)malloc(LEN); p=p->next; } else { p->ch=0; p->next=NULL; break; } } string=head; } void print(struct link *head) { struct link *p; p=head; while(p->next!=NULL) { printf("%c ",p->ch); p=p->next; } printf("/n"); } void del(struct link *head) { char a[1]={0}; struct link *p1,*p2; p1=head; printf("input the char you delete:"); scanf("%s",a); while(a[0]!=p1->ch&&p1->next!=NULL) { p2=p1; p1=p1->next; } if(p1==head) head=p1->next; else p2->next=p1->next; string=head; print(head); } void add(struct link *head) { struct link *p; char c[1]; printf("input the char you add:"); scanf("%s",c); p=head; while(p->next!=NULL) p=p->next; p->ch=c[0]; p->next=(struct link *)malloc(LEN); p=p->next; p->ch=0; p->next=NULL; print(head); } void main() { array(); creat(a); print(string); del(string); add(string); }