C language Article editing implementation code

Source: Internet
Author: User

Problem:

Article editing

Function: Enter a page of text, the program can count the number of words, numbers, spaces.
Static storage of a page of articles, a maximum of 80 characters per line, a total of n rows; (1) The number of English letters and spaces and the total words of the whole article are counted; (2) count the number of occurrences of a string in the article and output the number of times, and (3) Delete a substring and move the following characters forward.
The storage structure uses the linear table, and uses several sub-functions respectively to realize the corresponding function;
Enter the form and range of the data: You can enter uppercase, lowercase letters, any numbers, and punctuation.
Output form: (1) Branch output user input of each line character; (2) 4 lines output "All letters", "Number of Numbers", "number of spaces", "Total Words" (3) output Delete a string after the article;

The code is as follows:

#include <stdio.h>
#include <stdlib.h>
#include "string.h"
#include <time.h>
#define MAXSIZE 256
Insert operation of linked list

void Insertelem (char *sqlist,int*len,int index,char elem) {
if (index> (*len) | | index<0) {
printf ("error!");
Exit (1);
}else {
for (int i=*len;i>=index;i--)
Sqlist[i+1]=sqlist[i];
Sqlist[index]=elem;
*len=*len+1;
}


}

Delete operation of linked list

void Deleteelem (char *sqlist,int*len,int index) {
if (index> (*len) | | index<0) {
printf ("error!");
Exit (1);
}else
{
for (int i=index;i<*len;i++)
SQLIST[I]=SQLIST[I+1];
*len=*len-1;
}
}

void Initsqlist (char *sqlist) {
int index=0;
while (index<maxsize) {
Char Ch=getchar ();
if (ch== ' # ') {
Sqlist[index]=ch;
break;}
Sqlist[index]=ch;
index++;
}
}
int Sum_a (Char*sqlist,int len) {
int in_len=0;
for (int i=0;i<len;i++) {
if (sqlist[i]>= ' A ' &&sqlist[i]<= ' Z ' | | Sqlist[i]>= ' a ' &&sqlist[i]<= ' Z ') {
in_len++;
}
}
return In_len;
}
int Sum_b (Char*sqlist,int len) {
int in_len=0;
for (int i=0;i<len;i++) {
if (sqlist[i]== ') {
in_len++;
}
}
return In_len;
}
int sum (char*sqlist) {
int in_len=0;
while (sqlist[in_len]!= ' # ') {
in_len++;
}
return In_len;
}
int Sum_c (Char*sqlist,int len) {
int in_len=0;
for (int i=0;i<len;i++) {
if (sqlist[i]!=10) {
in_len++;
}

}
return In_len;
}
void Print_a (char *sqlist,int len) {
for (int i=0;i<len;i++) {
printf ("%c", Sqlist[i]);
}
printf ("\ n");
}
void Print_b (char *sqlist,int len) {
printf ("The total number of letters:%d\n", Sum_a (Sqlist,len));
printf ("Total number of spaces:%d\n", Sum_b (Sqlist,len));
printf ("Total number of words:%d\n", Sum_c (Sqlist,len));
}

int Sun_char (char*sqlist,int len1,char* substr,int len2) {
int flag=0;
for (int i=0;i<len1;i++)
{
for (int j=0;j<len2;j++) {
if (Sqlist[i+j]!=substr[j])
Break
}
if (J==LEN2)
{
flag++;
}
}
return flag;
}

void Delete_sub_str (char *str, char *sub_str, int *len1,int *len2);
int main () {
Char Sqlist[maxsize];
printf ("Please enter the article you are writing to end with the character ' # '!") \ n ");
Initsqlist (sqlist);
int len=sum (sqlist);
printf ("you wrote the following: \ n");
Print_a (Sqlist,len);
Print_b (Sqlist,len);
Char Sub[maxsize];
Char Sub1[maxsize];
Go
printf ("Input 1 means query, input 2 means delete:");
int var=0;
scanf ("%d", &var);
Switch (VAR) {
Case 1:
printf ("Please enter the string you are looking for: \ n");
scanf ("%s", sub);
printf ("The number of strings you want to query in the article is as follows: \n%d\n", Sun_char (Sqlist,len,sub,strlen (sub));
Break
Case 2:
printf ("Please enter the string you want to delete \ n");
scanf ("%s", sub1);
int Len2=strlen (SUB1);
Delete_sub_str (SqList, Sub1, &len,&len2);
Break
}

printf ("Do you want to continue?" \ n Enter 1 to continue ");
scanf ("%d", &var);
if (var==1) {
Goto go;
}else
printf ("program operation finished!");
return 0;

}

void Delete_sub_str (char *str, char *sub_str, int *len1,int *len2)
{

int i,j,succ;
i=0;succ=0; /* Use the I-scan body t,succ to match the success flag */
while ((i<=*len1-*len2+1) && (!SUCC))
{
J=0;succ=1; /* with J-Scan mode p*/
while ((j<=*len2-1) &&SUCC)
if (Sub_str[j]==str[i+j]) j + +;
else succ=0;
i++;
}
if (SUCC)
{
For (j=0;j< (*len1-*len2-1); j + +)
{
STR[I-1]=STR[I+*LEN2-1];
i++;
}
*len1=*len1-*len2;
printf ("Delete results as follows: \ n");
for (i=0;i<*len1;i++)
{
printf ("%c", Str[i]);
}
printf ("\ n");
}
else printf ("\ n Error! There are no substrings to match the string! ");

}

C language Article editing implementation code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.