Re: count2.asm



On Mon, 25 Jul 2005 13:58:46 -0400, Frank Kotler

this is my not tested one in C

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

static char list[256]={0};

void init(void)
{char *p;
char *a1="aeiou", *a2="BCDFGHJKLMNPQRSTVWXZ",
*a3="bcdfghjklmnpqrstvwxz",
*a4="0123456789",
*a5="!\'#$%&', \"()*+,-./:;<=>?@[\\]^_`{|}~", *a6="AEIOU",
*a7="\t", *a8=" ", *a9="\n";

/***********************************/
for(p=a1; *p; ++p) list[*p]=1;
for(p=a2; *p; ++p) list[*p]=2;
for(p=a3; *p; ++p) list[*p]=3;
for(p=a4; *p; ++p) list[*p]=4;
for(p=a5; *p; ++p) list[*p]=5;
for(p=a6; *p; ++p) list[*p]=6;
list[*a7]=7; list[*a8]=8; list[*a9]=9;
}

long unsigned contatori[11]={0};
long unsigned words=0;

int main(int x, char** a)
{char buff[1090], *to, cc,*p, o;
FILE *f_in;
int c, j;
unsigned long tmp, tmp1;
/**********************************/
if(x!=0 && a!=0 && a[0]!=0) to=a[1];
else to="";

if( !(x==2) || *to==0)
{printf("USO:\n>nome_prog nome_file_in "); return 0;}

f_in=fopen(to, "r");
if(f_in==0) {printf("impossibile aprire il file %s\n", to);
return 0;
}
init();
while( (c=fread(buff, 1, 1024, f_in)) > 0)
{p=buff;
for(j=0, cc=' '; j<c; ++j)
{o=*p; /* this is not ok when "paro=\nla" */
if(isspace(o) && isalnum(cc)) ++words;
++contatori[list[o]];
cc=o; ++p;
}
}

if( fclose(f_in)== EOF )
{printf("Errori nel leggere il file\n");
return 0;
}

printf("\nUpper case vowels: %lu\n",contatori[6]);
printf("Lower case vowels: %lu\n", contatori[1]);
printf("Total vowels: %lu\n",
tmp=contatori[1]+contatori[6]);
printf("Upper case consonants: %lu\n", contatori[2]);
printf("Lower case consonants: %lu\n", contatori[3]);
printf("Total consonants: %lu\n",
tmp1=contatori[2]+contatori[3]);

printf("Total alpha characters: %lu\n", tmp+tmp1);
printf("Numerals: %lu\n", contatori[4]);
printf("Total punctuation: %lu\n", contatori[5]);
printf("Total words: %lu\n", words);
printf("Tabs: %lu\n", contatori[7]);
printf("Spaces: %lu\n", contatori[8]);
printf("Carriage Returns: %lu\n", contatori[9]);
/* what is linefeed ? */
for(j=0, tmp=0; j<11; ++j)
tmp+= contatori[j];
printf("Total number of chars: %lu\n", tmp);
return 0;
}



.



Relevant Pages