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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void setSequence(char *filename){
int SIZE = 512;
char ligne[SIZE];
char *Sequence = malloc(SIZE * sizeof(*Sequence));
if(Sequence==NULL){
fprintf(stderr, "Memory allocation error !\n");
exit(2);
}
FILE *monFichier = fopen(filename, "r");
if (monFichier == NULL) {
fprintf(stderr, "Can not open file %s\n", filename);
exit(3);
}
char *file = LireMot(monFichier);
if(file==NULL){
fprintf(stderr, "Can not access to %s\n", filename);
exit(3);
}
while(fgets(ligne, sizeof ligne, file)){
if(ligne[0] != '>')
{
strcat(Sequence, ligne);
char *tmp = (char *)malloc(SIZE*sizeof(char));
if(tmp==NULL){
fprintf(stderr, "Memory allocation error !\n");
exit(2);
}
SIZE*=2;
tmp = Sequence;
Sequence = (char *)realloc(Sequence, SIZE*sizeof(char));
if(Sequence==NULL){
fprintf(stderr, "Memory allocation error !\n");
exit(2);
}
Sequence = tmp;
free(tmp);
}
}
printf("%s\n", Sequence);
} |
Partager