第七章20题关键代码

来源:互联网 发布:msp430编程 编辑:程序博客网 时间:2024/04/30 07:12

typedef struct linknode
{
 char data;
 struct linknode *pNext;
}linkstring;

void MyChange(linkstring * S,char c,char s)
{
 while(S){
  if(S->data==c)
   S->data=s;
  S=S->pNext;
 }
 return;
}
void display(linkstring *S)
{
 while(S){
  printf("%c",S->data);
  S=S->pNext;
 }
 printf("/n");
}

//关键函数MyChange

//一下是初始化函数

linkstring * InitLinkstring()
{
 char ch;
 printf("Input the String (end whit space): ");
 ch=getche();
 linkstring * h, *p,*temp;
 p=(linkstring*)malloc(sizeof(linkstring));
 h=p;
 p->data=ch;
 p->pNext=NULL;
 while(ch!=' '){
  temp=(linkstring*)malloc(sizeof(linkstring));
  ch=getche();
  temp->data=ch;
  p->pNext=temp;
  p=temp;
  p->pNext=NULL;
 }
 printf("/n");
 return h;
}

原创粉丝点击