To process the file as follows:
Code:
AATTTTAATATA
CGGCCCCCGC
...
I define a struct as follows:
Code:
struct SNPData
{
char** SNPData;
//char** MajOrMin;
};
int main()
{
struct SNPData *s;
s = readSNPData("1.txt");
return 0;
}
but I don't know how to malloc memory to SNPData.
part code
Code:
/* read into memory from input file */
struct SNPData* readSNPData(char *input)
{
struct SNPData *SNPs;
FILE *fp;
fp = fopen(input,"r");
int i = 0;
int isKnownLen = 0;
while(! feof(fp))
{
if ( isKnownLen = 0 )
{
char *buf = (char *) malloc( 1*sizeof(char) );
char c;
while( (c = fgetc(fp)) != '\n' )
{
*(buf+i) = c;
realloc(buf,i+2);
++i;
}
isKnownLen = 1;
}else
{
//fscanf(fp,"%s",tmp);
char *buf = (char *) malloc( i*sizeof(char) );
fgets(buf,i,fp);
}
}
fclose(fp);
}
how to malloc memory to SNPData and where is the codes mallocing memory added?