根据你的意思,重写了一份代码,你看看是不是这样的?
程序代码:
#include<stdio.h>
#include<stdlib.h>
typedef struct st
{
char data;
struct st *next;
}st;
st *new_line();
st *xiugai(st *head,char old,char new_data);
void print(st *head);
int main(void)
{
st *head;
char old,new_data;
head=new_line();
print(head);
scanf("%c %c",&old,&new_data);
head=xiugai(head,old,new_data);
print(head);
return 0;
}
st *new_line()
{
st *head,*pr,*p;
int i;
head=pr=NULL;
for(i=0;i<10;++i)
{
while((p=(st *)malloc(sizeof(st)))==NULL)
;
if(!i)
{
head=pr=p;
}
else
{
pr->next=p;
pr=p;
}
p->data=getchar();
while(getchar()!='\n');
}
p->next=NULL;
return head;
}
st *xiugai(st *head,char old,char new_data)
{
st *p;
p=head;
if(head==NULL)
{
return NULL;
}
while(p)
{
if(p->data==old)
{
p->data=new_data;
break;
}
p=p->next;
}
return head;
}
void print(st *head)
{
st *p=head;
while(p)
{
putchar(p->data);
p=p->next;
}
}
[
本帖最后由 广陵绝唱 于 2010-8-14 17:46 编辑 ]