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 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define my_realloc(a, b) realloc(a, b)
#define my_malloc(a) malloc(a)
typedef struct s_params
{
char **fapo, **fcomplex, **fligan;
int nfiles;
float ashape_min_size, ashape_max_size;
}
s_params;
int add_prot (char *apo, char *complex, char *ligan, s_params * par)
{
FILE *f = fopen (apo, "r");
int nm1;
if (f != NULL)
{
fclose (f);
f = fopen (complex, "r");
if (f)
{
nm1 = par->nfiles;
par->nfiles += 1;
par->fapo =my_realloc (par->fapo, (par->nfiles) * sizeof (char *));
par->fligan =my_realloc (par->fligan,
(par->nfiles) * sizeof (char *));
par->fcomplex =my_realloc (par->fcomplex,
(par->nfiles) * sizeof (char *));
par->fapo[nm1] = my_malloc ((strlen (apo) + 1) * sizeof (char));
par->fcomplex[nm1] =
my_malloc ((strlen (complex) + 1) * sizeof (char));
par->fligan[nm1] = my_malloc ((strlen (ligan) + 1) * sizeof (char));
strcpy (par->fapo[nm1], apo);
strcpy (par->fcomplex[nm1], complex);
strcpy (par->fligan[nm1], ligan);
fclose (f);
}
else
return 0;
}
else
return 0;
return 1;
}
int add_list_data (char const *str_list_file, s_params * par)
{
FILE *f;
int n, nread = 0, status;
char buf[150], apobuf[10], ligbuf[50], complexbuf[50];
f = fopen (str_list_file, "r");
if (f)
{
while (fgets (buf, 150, f))
{
n = par->nfiles;
status = sscanf (buf, "%s %s %s", apobuf, complexbuf, ligbuf);
if (status == 3)
{
nread += add_prot (apobuf, complexbuf, ligbuf, par);
}
}
}
// FLAG
return (nread);
}
int main (void)
{
char str_list_file[128] = "ABCD";
s_params par = { 0 };
int err = add_list_data (str_list_file, &par);
printf ("err = %d\n", err);
return EXIT_SUCCESS;
} |
Partager