-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCountVal.cpp
49 lines (40 loc) · 1.06 KB
/
CountVal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
int CountVal(char *argv[])
{
int type;
char FileName[200];
char str[200];
long int DiffLocation;
long int DiffValue;
strcpy(FileName, argv[1]);
strcat(FileName, "DiffValSeq");
FILE *fpRead = fopen(FileName, "r");
if (fpRead == NULL) {
fprintf(stderr, "Can't open file %s!\n",FileName);
exit(1);
}
long int Size;
int Nd=18;
int SetMaxDiff = exp2(Nd); //set max alphabet size
int Map[SetMaxDiff];
memset(Map,0,SetMaxDiff*sizeof(int));
int Diff;
while(!feof(fpRead)){
fscanf(fpRead,"%ld ", &DiffValue);
++Map[mydiff(DiffValue)];
}
fclose(fpRead);
unsigned int i;
strcpy(FileName, argv[1]);
strcat(FileName,"DiffVal");
FILE *fpWriteDiff = fopen(FileName, "w");
if (fpWriteDiff == NULL) {
fprintf(stderr, "Can't open file %s!\n",FileName);
exit(1);
}
fprintf(fpWriteDiff, "Diff\t\t CountDiff\n");
for(i=0;i<SetMaxDiff;++i)
if(Map[i] != 0)
fprintf(fpWriteDiff, "%ld %d \n", getdiff(i), Map[i]);
fclose(fpWriteDiff);
return 1;
}