#include<stdio.h>
main()
{
FILE *f=fopen("Number.dat","w");
int a[8],i;
for(i=0;i<8;i++)
{
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
fwrite(a,sizeof(int),8,f);
fclose(f);
}
Compile: cc filewrite.c
Run : ./a.out
Histogram.c
#include<stdio.h>main(int argc,char *argv[])
{
int a[8],j,i,count[20],flag=0;
FILE *f=fopen(argv[1],"r");
fread(a,sizeof(int),8,f);
for(i=0;i<8;i++)
{
count[i]=0;
for(j=0;j<8;j++)
{
if(a[i]==a[j])
count[i]++;
}
flag=0;
for(j=0;j<=i;j++)
{
if((a[i]==a[j])&& (i!=j))
flag=1;
}
if(!flag)
{
printf("\n%d\t",a[i]);
for(j=0;j<count[i];j++)
printf("*");
}
}
printf("\n");
fclose(f);
}
Compile: cc Histogram.c
Run: ./a.out Number.dat