-
大小: 4KB文件類型: .c金幣: 1下載: 0 次發(fā)布日期: 2021-06-09
- 語(yǔ)言: 其他
- 標(biāo)簽: 鏈串??數(shù)據(jù)結(jié)構(gòu)??
資源簡(jiǎn)介
鏈串實(shí)現(xiàn)的文本編輯器,封裝了各種操作的方法,如求長(zhǎng)度,插入字符等等。
代碼片段和文件信息
#include?“stdio.h“
struct?linkNode{
char?value;
struct?linkNode*?next;
};
struct?linkNode*?createlink();
int?addstr(struct?linkNode*?headNode?char?c);
void?printstr(struct?linkNode*?headNode);
main(){
char?input;
struct?linkNode*?headNode;
headNode=createlink();
do{
input=getch();
if((input>=‘0‘&&input<=‘9‘)||(input>=‘A‘&&input<=‘Z‘)||(input>=‘a(chǎn)‘&&input<=‘z‘)||input==‘?‘){
printf(“%c“input);
addstr(headNodeinput);
}
if(input==‘\b‘){
printf(“\b?\b“);
}
if(input==‘\r‘){
printf(“\r\n“);
addstr(headNodeinput);
}
}while(input!=27)??;
deletestr(headNode“aaa“);
/*?replacestr(headNode“aaa““cccc“);*/
printf(“\n“);
printstr(headNode);
printf(“\nspace?in?the?passage:%d“?countspace(headNode));
printf(“\nchar?in?the?passage:%d“?countchar(headNode));
printf(“\nword?in?the?passage:%d“?countword(headNode));
printf(“\nnumber?in?the?passage:%d“?countnum(headNode));
getch();
}
struct?linkNode*?createlink(){
struct?linkNode*?h;
h=(struct?linkNode*)malloc(sizeof(struct?linkNode));
h->next=NULL????;
h->value=NULL;
return?h;
}
int?addstr(struct?linkNode*?headNodechar?c){
struct?linkNode*?unit;
struct?linkNode*??p;
unit=(struct?linkNode*)malloc(sizeof(struct?linkNode));
unit->next=NULL;
unit->value=c;
p=headNode;
while(p->next!=NULL)p=p->next;?/*move?to?end;*/
p->next=unit;
}
void?printstr(struct?linkNode*?headNode){
struct?linkNode*?p;
char?input;
p=headNode;
while(p->next!=NULL){
p=p->next;
input=p->value;
if((input>=‘0‘&&input<=‘9‘)||(input>=‘A‘&&input<=‘Z‘)||(input>=‘a(chǎn)‘&&input<=‘z‘)||input==‘?‘){
printf(“%c“input);???}
if(input==‘\r‘){
printf(“\r\n“);
}
}
}
int?countspace(struct?linkNode*?headNode){
struct?linkNode*?p;
char?input;
int????count=0;
p=headNode;
while(p->next!=NULL){
p=p->next;
input=p->value;
if(input==‘?‘){
count++;
}
}
return?count;
}
int?countchar(struct?linkNode*?headNode){
struct?linkNode*?p;
char?input;
int????count=0;
p=headNode;
while(p->next!=NULL){
p=p->
評(píng)論
共有 條評(píng)論