?? 21.cpp
字號:
#include<iostream>
#include<string>
using namespace std;
struct chNode{
char c;
chNode *next;
};//定義結構體變量;
void displayStr(chNode *p)//屏幕顯示字符串函數
{
while(p!=NULL)
{
cout<<p->c;
p=p->next;
}
cout<<endl;
}
void getStr(char *b,chNode *p)//屏幕顯示以p指向其首的一個字符;
{
while(p!=NULL)
{
*b=p->c;
p=p->next;
cout<<*b;
b++;
}
cout<<endl;
}
void catStr(char *a,chNode *p)
{
while(*a!='\0')
{
chNode *q,*w;//開辟另一個新的具有chNode結構的指針變量
q=new chNode;
q->c=*a; //賦初值
q->next=NULL;
if(p==NULL)//當p指向的值為空的時候,將p和q連接,使p指向q的開頭
p=q;
else
{
w=p;
while(w->next!=NULL)
{
w=w->next;//當w不為空時,逐個取輸入的字符串的值
}
w->next=q;
}
a++;
}
displayStr(p);//屏幕上顯示串接后的字符串;
}
void main()
{
chNode *p;
p=new chNode;
p->c='z';//規定p指向的字符為z;
p->next=NULL;
char *a,b[100];//字符數組b用來存放輸入的字符;
char m[100];
cout<<"輸入字符串:\n";
gets(m);
cout<<"指針p指向的字符為:\n";
getStr(b,p);
a=m;//定義a為指向m字符數組的指針
cout<<"你將得到輸入的字符串與p指向的字符的串接字符串:\n";
catStr(a,p);
cout<<"數組b中存放的字符串為:"<<endl;
catStr(a,p);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -