-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisoread.c
75 lines (56 loc) · 1.06 KB
/
isoread.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#define MAX_SIZE 1024
int dump_buffer(void *buf, int buf_size)
{
int i;
for (i = 0; i < buf_size; ++i)
printf("%c", ((char *) buf) [i]);
return 0;
}
int main(int argc, char *argv[])
{
FILE *fp;
char buf[MAX_SIZE];
unsigned long fileLen;
if (argc < 2) {
printf("Error. No find file.\n");
return 2;
}
fp = fopen(argv[1], "rb");
if (fp == NULL) {
perror("fopen()");
return 3;
}
fseek(fp, 0, SEEK_END);
fileLen = ftell(fp);
fseek(fp, 0, SEEK_SET);
if (buf[MAX_SIZE] == (char)malloc(MAX_SIZE *fileLen))
printf("%c", buf[MAX_SIZE]);
if (buf == NULL) {
printf("Memory allocation error!");
fclose(fp);
return 4;
}
fread(buf, fileLen, 1, fp);
printf("value is %s\n", buf);
dump_buffer(&buf, fileLen);
fclose(fp);
return 0;
}
// free(buf);
/*
while (!feof(fp)) {
char n, k;
n = fscanf(fp, "%c", &k);
printf("%c %c\n", n, k);
n++;
}
printf("\n");
fclose(fp);
return 0;
}
*/