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

typedef struct _list_{
  int car;
  int cpt;
  struct _list_ * svt;
} enrliste, *liste;

FILE* source;
liste info = NULL;

void option(int argc, char *argv[])
{   int opt;
    while ( ( opt = getopt(argc, argv, "f:h")) != -1 ) {
	switch ( opt ) {
	case 'f':
	    source = fopen(optarg, "r");
	    if (source == NULL) exit( 1 );
            break;
	case 'h':
	  fprintf(stderr, "Usage: %s [-f fichier]", argv[0]);
	default :
	    exit( 1 );
	}
    }
}
void traitement( int car )
{ liste aux;
    aux = info;
    while ( aux ) {
      if ( aux->car == car  ) {
	aux->cpt++;
	return;
      }
      aux = aux -> svt;
    }
    aux = ( liste ) malloc( sizeof(enrliste) );
    aux->svt = info; aux->car = car; aux->cpt = 1; info = aux;
}

int main(int argc, char *argv[])
{ int car;
    source = stdin;
    option( argc, argv );
    while ( feof(source) == 0 ) {
	car = fgetc( source );
	if (car != EOF) 
	  traitement( car );
    }
    fclose(source);
    while ( info ) {
      printf("[%c:%3d:%d]->", info->car, info->car, info->cpt );
      info = info->svt;
    }
    printf("\n");
    return 0;
}
