This web page requires JavaScript to be enabled.

JavaScript is an object-oriented computer programming language commonly used to create interactive effects within web browsers.

How to enable JavaScript?

Đếm tần suất 1 kí tự trong 1 file

10cth1-2 October 27, 2010 Nam Le 0
# include <stdio.h>
# include <string.h>
main()
{
    FILE *fp;
    char in[100];
    long int freq[257];
    int i;

    printf("\nFile frequency table generator\n\n");

    printf("\nInput file:");
    scanf("%s",in);
    fp=fopen(in,"rb");
    if(fp==NULL)
    {
        printf("\nCould not open input file.Aborting\n");
        return 1;
    }

    for(i=0;i<257;i++)
        freq[i]=0;

    while(i=fgetc(fp),i!=EOF)
    {
        freq[i]++;
    }
    fcloseall();

    fp=fopen("count.txt","w");
    fprintf(fp,"\nCharacter frequency table of %s\n",in);
    fprintf(fp,"\nCharacter ASCII frequency\n\n");

    for(i=0; i<256; i++)
    {
        if(i==26)
        {
            fprintf(fp,"\t    26\t  %ld\n",freq[26]);
        }
        else if(i==9)
        {
            fprintf(fp,"\t    9\t  %ld",freq[9]);
        }
        else if(i<10)
        {
            fprintf(fp,"%c\t    %d\t  %ld\n",i,i,freq[i]);
        }
        else if(i<100)
        {
            fprintf(fp,"%c\t    %d\t  %ld\n",i,i,freq[i]);
        }
        else
        {
            fprintf(fp,"%c\t    %d\t  %ld\n",i,i,freq[i]);
        }
    }

    fcloseall();
    printf("\nFrequency table copied to count.txt\n");
}

Last modified on December 19th, 2020 at 7:10 pm

Nam Le
lequocnam



0 responds

Leave a Reply

Your email address will not be published. Required fields are marked *