I tried your code out....I couldnt really tell what exactly was causing the segfault, but it works for me after some slight adjustments...
Code:
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 50
struct data
{
int id;
char title [SIZE];
char gene [SIZE];
char express [SIZE];
char chrom [SIZE];
int scount;
};
int main ()
{
int i, j;
struct data genedata[SIZE];
FILE * dataPtr;
char line [SIZE];
if(( dataPtr = fopen("hstest.txt", "r")) == NULL)
{
printf("File could not be opened.\n");
}
else
{
i=-1;
while(fgets(line, SIZE, dataPtr) && i<SIZE)
{
char *p = strchr(line,'\n');
if (p != NULL)
*p='\0';
if (strncmp(line,"//",2) == 0)
i++;
if (strncmp(line, "ID",2) == 0)
genedata[i].id = atoi(line+3);
else if (strncmp(line, "TITLE",5) == 0)
strcpy(genedata[i].title, line);
else if (strncmp(line, "GENE",4) == 0)
strcpy(genedata[i].gene, line);
else if (strncmp(line, "EXPRESS",7) == 0)
strcpy(genedata[i].express, line);
else if (strncmp(line, "CHROMOSOME",10) == 0)
strcpy(genedata[i].chrom, line);
else if (strncmp(line, "SCOUNT",6) == 0)
genedata[i].scount = atoi(line+7);
} /*close while*/
fclose (dataPtr);
i++;
if(( dataPtr = fopen( "records.dat", "w")) == NULL)
printf("error");
else {
for (j = 0;j < i;j++)
fprintf(dataPtr,"[id:%d]\t%s\t%s\t%s\t%s %d\n\n",
genedata[j].id,genedata[j].title,genedata[j].gene,
genedata[j].express,genedata[j].chrom,genedata[j].scount);
fclose (dataPtr);
}
} /*close else*/
return 0;
}