(UP)

This code was provoked by the series on Channel 4 about encryption and designed to help to solve 'The Code Challenge' from the series. When compiled the code reads inputfile.txt and tells how frequently each letter was used.
(code, sample-in, sample-out)

#include <stdio.h>
#include <string.h>


void main(void)
{
int x,i;
char c;
int xxx[256];
FILE *fpO;
char filename[30];

sprintf(filename,"inputfile.txt");
fpO=fopen(filename,"r");

for (i=0;i<=255;i++)
{
xxx[i] = 0;
}

while (c != 255)
{
fflush(fpO);
c=fgetc(fpO);
x=c;
xxx[x]++;
/* printf("%c %d\n",x,x);*/
}
fclose(fpO);
for (i=65;i<=90;i++)
{
printf ("%c - %d\n",i,xxx[i]+xxx[i+32]);
}
printf ("\n");
for (i=65;i<=90;i++)
{
printf ("%d\t%d\n",i-64,xxx[i]+xxx[i+32]);
}

for (i=65;i<=90;i++)
{
printf ("%c ",i);
}
printf ("\n");
for (i=65;i<=90;i++)
{
printf ("%d ",xxx[i]+xxx[i+32]);
}
printf ("\n");
}

(c) Viktor Yarmolenko, viktor.yarmolenko@physics.org


(UP)








  Science
Programming
Other Activities






©2002-2004 Viktor Yarmolenko