DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Conteo De Caracteres

09.22.2006
| 3923 views |
  • submit to reddit
        Este pedazo de codigo cuenta los caracteres de un archivo

this code count the chars of a file.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    int cont[257];
    int t;
    FILE *ent;
    
    for (t=0;t<257;t++)
        cont[t]=0;
      
    ent=fopen("input.txt","r");
//    printf("Se abrio el archivo :P\n");
    do {
        t = fgetc(ent);
        cont[t]++;
    } while (!feof(ent));
    fclose(ent);

    for (t=0;t<257;t++){
        printf("Caracter %i se repitio %i veces\n", t, cont[t]);
    }

    
//  system("PAUSE");	
  return 0;
}