⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wenzhangbianji.txt

📁 本程序可以实现的功能是输入一页文字后
💻 TXT
字号:
#include <stdio.h>
#include <malloc.h>
#include <ctype.h>
#include <string.h>
#define MAX 80

typedef struct line
{
	char s[80];
	struct line *next;
}LINE;

int row=0;		//总行数
int letter=0;		//全部字母数
int number=0;		//数字个数
int space=0;		//空格个数
int word=0;			//文章总字数

void out_data();

char *readline(char s[MAX])
{
	char c;
	int i=0;
	while((c=getchar()) !='\n'){            //输入字符串   
		s[i++]=c;
	}
	s[i]='\0';
	return s;
}

LINE  *input(LINE *head)
{
	LINE *p,*q;
	char *temp,s[MAX];
	while(1){
		if(row == 0){
			p=q=head=(LINE *)malloc(sizeof(LINE));    //建立线形表并将输入内容存储
			head->next=NULL;
			}
		else
			p=(LINE *)malloc(sizeof(LINE));
		p->next = NULL;
		temp = readline(s);
		strcpy(p->s,temp);
		if(p->s[0] == '#')                    //文章输入以#号键结束
			break;
		row++;
		q->next = p;
		q = p;
	}
	return head;
}
void count(LINE *head)
{
	int i=0;
	while(head){
		for(i=0 ;head->s[i] ;i++){
			if(isalpha(head->s[i])){		//字母
				letter++;
				word++;
			}
			else if(isdigit(head->s[i])){		//数字
				number++;
				word++;
			}
			else if(head->s[i] == ' '){		//空格
				space++;
			}
		}
		head = head->next;
	}
	out_data();
}
void ouput(LINE *head)
{
	while(head){
		printf("%s\n",head->s);
		head=head->next;
	}
}
void out_data()
{
	printf("全部字母数: %d\n",letter);
	printf("数字  个数: %d\n",number);
	printf("空格  个数: %d\n",space);
	printf("文章总字数: %d\n",word);

} 
char *delson(char *s,char *d)
{
	char *p=NULL;
	char temp[80];	
	static char str[80];
	p=strstr(s,d);             //查找要删除字符串在s中出现的首位置
	if(p){
		while(p){
			strncpy(temp,s,strlen(s)-strlen(p));   //将要删除字符复制到temp中
			temp[strlen(s)-strlen(p)]='\0';
			p=p+strlen(d);
			strcat(temp,p);
			temp[strlen(s)-strlen(d)+1]='\0';
			s=temp;
			p=strstr(s,d);
		}
		strcpy(str,temp);
	}
	else
		strcpy(str,s);
	return str;
}
void del_data(LINE *head)
{
	char s[MAX],*p,*q,*result=NULL;
	int i=0,length=0,j=0;
	printf("请输入要删除的字符串: ");
	scanf("%s",s);
	q=s;
	length=strlen(s);
	while(head)
	{
		p=head->s;                        //删除输入的字符串
		result=delson(p,q);
		strcpy(head->s,result);		
		head=head->next;
	}
}

int main(void)
{
	LINE *head=NULL;
	head=input(head);
	ouput(head);
	count(head);
	del_data(head);
	ouput(head);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -