-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadIntBin.c
More file actions
77 lines (68 loc) · 1.75 KB
/
readIntBin.c
File metadata and controls
77 lines (68 loc) · 1.75 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <stdlib.h>
#define BLOCK_SIZE 4096
#define BUFFERS 100
int main(){
int num1;
int count;
int attributes[50][2];
double num2;
char data2[50];
FILE *ptr_myfile;
FILE *ptr_myfile1;
//Location of bin file
char path[64];
printf("Enter no. file path to read : ");
scanf("%s",path);
int rn;
printf("Enter no. rows to read : ");
scanf("%d",&rn);
ptr_myfile=fopen(path, "rb");
if (!ptr_myfile)
{
printf("Unable to open file!");
return 1;
}
int memloc=0;
unsigned int noofattr;
int type,length;
fread(&noofattr,sizeof(unsigned int),1,ptr_myfile);
//printf("No of attributes: %d",noofattr);
//printf("\n\n----------Metadata---------------\n\n");
for(count=0;count<noofattr;count++){
fread(&type,sizeof(int),1,ptr_myfile);
fread(&length,sizeof(int),1,ptr_myfile);
attributes[count][0]=type;
attributes[count][1]=length;
//printf("Attribute %d\ntype: %d length: %d\n\n",count+1,type,length);
}
// sprintf(path, "/home/revanth/Desktop/temp/SortedRuns/run_%d_out%d.bin", ln, fn);
// ptr_myfile1=fopen(path,"rb");
// if (!ptr_myfile1)
// {
// printf("Unable to open file!");
// return 1;
// }
int returnval=1;
int iter = 0;
while(returnval && iter< rn)
{
for(count=0;count<noofattr;count++)
{
switch (attributes[count][0]){
case 1: returnval=fread(&num1,attributes[count][1],1,ptr_myfile);
if (returnval) printf("%d ",num1);
break;
case 2: returnval=fread(&num2,attributes[count][1],1,ptr_myfile);
if (returnval) printf("%f ",num2);
break;
case 3: returnval=fread(data2,attributes[count][1],1,ptr_myfile);
if (returnval) printf("%s ",data2);
break;
}
}
if (returnval) printf("\n");
iter++;
}
printf("num records %d\n",iter);
}