-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadFile.c
More file actions
57 lines (42 loc) · 933 Bytes
/
readFile.c
File metadata and controls
57 lines (42 loc) · 933 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * readFile(FILE *fin, int *n);
char * readFile(FILE *fin, int *n) {
int BLOCK_READ_SIZE = 200;
char * txt, tmp;
int dim=8, read, i, j;
char buf[BLOCK_READ_SIZE];
(*n)=0;
txt = malloc (dim * BLOCK_READ_SIZE * sizeof(char));
if(!txt) {
return NULL;
}
while(fgets(buf, sizeof(buf), fin)) {
txt = strcat(txt,buf);
(*n)++;
if((*n)>=dim) {
dim *= 2;
txt = realloc(txt, dim * BLOCK_READ_SIZE * sizeof(char));
if(!txt){
return NULL;
}
}
}
txt = realloc (txt, (*n) * BLOCK_READ_SIZE * sizeof(char));
return txt;
}
int main(){
//char path[] = "dataset/dna_corto_pulito.txt";
char path[] = "dataset/ManuSporny-genome.txt";
char* txt;
int n=0;
FILE *fin;
if((fin = fopen(path, "r"))==NULL){
printf("Errore nell'apertura del file!");
return -1;
}
txt = readFile(fin, &n);
//printf("%s",txt);
return 0;
}