统计英文文章中空格数,单词数,字符数,并删除指定字符 (c语言)

需要将txt英文文件同源文件放在同一个文件夹中。

#include<stdio.h>
#include <string.h>
typedef struct
{
    int byte[15];
} WORD;
typedef struct

    WORD word[2000];
    int final;
}CHAPTER;          
CHAPTER *load(CHAPTER *chapter)
{
    FILE *fp;
    char c;
    char b[15];
    int i;
    int i2;
    if((fp=fopen("test two.txt","rt+"))==NULL)
    {
     printf("cannot open");
     return 0;
     }
     chapter->final=0;     
     while(!feof(fp))
     {
         c=fgetc(fp);
             if(c>64&&c<123)
             {
                 fseek(fp,-1,1);
                 fscanf(fp,"%s",b);
                 for(i2=0;b[i2]!=0;i2++)
                 {
                 }
                 if(!(b[i2-1]>64&&b[i2-1]<123))
                 {
                     b[i2-1]=0;
                     fseek(fp,-1,1);
                 }
                 i=0;
                 while(b[i]!=0)
                 {
                     chapter->word[chapter->final].byte[i]=b[i];
                     i++;
                 }
                 chapter->word[chapter->final].byte[i]=b[i];
                 chapter->final++;
              }
              else
              {
                  chapter->word[chapter->final].byte[0]=c;
                  chapter->word[chapter->final].byte[1]=0;
                  chapter->final++;
              }
        
     }
     return chapter;
}
void printchapter(CHAPTER *chapter)
{
    int j,k;
    char b[15];
    for (j=0;j<chapter->final;j++)
    {
       
        for(k=0;chapter->word[j].byte[k]!=0;k++)
        {
            b[k]=chapter->word[j].byte[k];
        }
        b[k]=chapter->word[j].byte[k];
        printf("%s",b);
    }
    printf("\n");
}
void deletestr(CHAPTER *chapter)
{
    int j,k;
    char b[15],input[15];
    printf("please input the word your want to delete:");
    scanf("%s",input);
    for (j=0;j<chapter->final;j++)
    {
       
        for(k=0;chapter->word[j].byte[k]!=0;k++)
        {
            b[k]=chapter->word[j].byte[k];
        }
        b[k]=chapter->word[j].byte[k];
        if(!strcmp(b,input))
        {
            chapter->word[j].byte[0]=0;   /*删除字符串*/
        }
    }
}
void record(CHAPTER *chapter)
{
    int j,k;
    int lettersum=0;
    int numbersum=0;
    int spacesum=0;
    int wordsum=0;
    char b[15];
    for (j=0;j<chapter->final;j++)
    {
        for(k=0;chapter->word[j].byte[k]!=0;k++)
        {
            b[k]=chapter->word[j].byte[k];


            if(47<b[k]&&b[k]<58)
            {
                numbersum++;
            }
            if(64<b[k]&&b[k]<123)
            {
                lettersum++;
            }
            if(b[k]==' ')
            {
                spacesum++;
            }

        }
        b[k]=chapter->word[j].byte[k];
        if(64<b[0]&&b[0]<123)
        {
            wordsum++;
        }
    }
    printf("numbersum: %d\n",numbersum);
    printf("lettersum: %d\n",lettersum);
    printf("wordsum: %d\n",wordsum);
    printf("spacesum: %d\n",spacesum);
}
main()
{
    CHAPTER txt;
    load(&txt);
    printchapter(&txt);
    record(&txt);
    deletestr(&txt);
    printchapter(&txt);
    getchar();
}

输出

Five score years ago, a great American, in whose symbolicshadow we stand signed
the Emancipation Proclamation. This momentous decree came as a great beacon ligh
t of hope to millions of Negro slaves who had been seared in the flames of withe
ring injustice. It came as a joyous daybreak to end the long night of captivity.
 But one hundred years later, we must face the tragic fact that the Negro is sti
ll not free.
One hundred years later, the life of the Negro is still sadly crippled by the ma
nacles of segregation and the chains of discrimination. One hundred years later,
 the Negro lives on a lonely island of poverty in the midst of a vast ocean of m
aterial prosperity. One hundred years later, the Negro is still languishing in t
he corners of American society and finds himself an exile in his own land.
So we have come here today to dramatize an appalling condition. In a sense we ha
ve come to our nation's capital to cash a check. When the architects of our repu
blic wrote the magnificent words of the Constitution and the Declaration of Inde
pendence, they were signing a promissory note to which every American was to fal
l heir.
This note was a promise that all men would be guaranteed the inalienable rights
of life, liberty, and the pursuit of happiness. It is obvious today that America
 has defaulted on this promissory note insofar as her citizens of color are conc
erned. Instead of honoring this sacred obligation, America has given the Negro p
eople a bad check which has come back marked "insufficient funds." But we refuse
 to believe that the bank of justice is bankrupt. We refuse to believe that ther
e are insufficient funds in the great vaults of opportunity of this nation.
So we have come to cash this check -- a check that will give us upon demand the
riches of freedom and the security of justice. We have also come to this hallowe
d spot to remind America of the fierce urgency of now. This is no time to engage
 in the luxury of cooling off or to take the tranquilizing drug of gradualism. N
ow is the time to rise from the dark and desolate valley of segregation to the s
unlit path of racial justice. Now is the time to open the doors of opportunity t
o all of God's children. Now is the time to lift our nation from the quicksands
of racial injustice to the solid rock of brotherhood.?
numbersum: 0
lettersum: 1856
wordsum: 412
spacesum: 408
please input the word your want to delete:,   //删除逗号

Five score years ago a great American in whose symbolicshadow we stand signed th
e Emancipation Proclamation. This momentous decree came as a great beacon light
of hope to millions of Negro slaves who had been seared in the flames of witheri
ng injustice. It came as a joyous daybreak to end the long night of captivity. B
ut one hundred years later we must face the tragic fact that the Negro is still
not free.
One hundred years later the life of the Negro is still sadly crippled by the man
acles of segregation and the chains of discrimination. One hundred years later t
he Negro lives on a lonely island of poverty in the midst of a vast ocean of mat
erial prosperity. One hundred years later the Negro is still languishing in the
corners of American society and finds himself an exile in his own land.
So we have come here today to dramatize an appalling condition. In a sense we ha
ve come to our nation's capital to cash a check. When the architects of our repu
blic wrote the magnificent words of the Constitution and the Declaration of Inde
pendence they were signing a promissory note to which every American was to fall
 heir.
This note was a promise that all men would be guaranteed the inalienable rights
of life liberty and the pursuit of happiness. It is obvious today that America h
as defaulted on this promissory note insofar as her citizens of color are concer
ned. Instead of honoring this sacred obligation America has given the Negro peop
le a bad check which has come back marked "insufficient funds." But we refuse to
 believe that the bank of justice is bankrupt. We refuse to believe that there a
re insufficient funds in the great vaults of opportunity of this nation.
So we have come to cash this check -- a check that will give us upon demand the
riches of freedom and the security of justice. We have also come to this hallowe
d spot to remind America of the fierce urgency of now. This is no time to engage
 in the luxury of cooling off or to take the tranquilizing drug of gradualism. N
ow is the time to rise from the dark and desolate valley of segregation to the s
unlit path of racial justice. Now is the time to open the doors of opportunity t
o all of God's children. Now is the time to lift our nation from the quicksands
of racial injustice to the solid rock of brotherhood.?
Press any key to continue

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值