07/11/25 07:54:28
>>128
まずファイルをてきとーに作る
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SIZE 20*10000
#define WAVLEN_MAX 10000
int main()
{
int p,t,i,m,n,s=SIZE;
char *buf,fname[]="test.dat";
FILE *fp;
srand(time(NULL));
t = (double)rand()/(RAND_MAX+1)*WAVLEN_MAX+1;
p = (double)rand()/(RAND_MAX+1)*t;
buf = (char*)malloc(t);
m=0;for(i=0;i<t;i++){buf[i] = rand()&1;m+=buf[i];}
if((fp=fopen(fname,"wt"))==NULL)exit(1);
n=0;for(i=0;i<s;i++){fprintf(fp,"%d",buf[(p+i)%t]);n+=buf[(p+i)%t];}
fprintf(fp,"\n");
fclose(fp);
free(buf);
printf("Total = %d (0:%d 1:%d) / T = %d (0:%d 1:%d)\n",s,s-n,n,t,t-m,m,p);
return 0;
}