here's an updated version of my program:
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=0;
int j=0;
struct data genedata[SIZE];
FILE *dataPtr;
char temp [SIZE];
char line [SIZE];
if(( dataPtr = fopen("Hs.data.filtered", "r")) == NULL)
{
printf("File could not be opened.\n");
}
else{
fscanf(dataPtr, "%s", temp);
if(strcmp(temp, "//") != 0){
fgets(line, SIZE, dataPtr);
}
while( !feof(dataPtr)){
if (strcmp(temp, "ID") == 0){
genedata[i].id = atoi(line);
}
if (strcmp(temp, "TITLE") == 0){
strcpy(genedata[i].title, line);
}
if (strcmp(temp, "GENE") == 0){
strcpy(genedata[i].gene, line);
}
if (strcmp(temp, "EXPRESS") == 0){
strcpy(genedata[i].express, line);
}
if (strcmp(temp, "CHROMOSOME") == 0){
strcpy(genedata[i].chrom, line);
}
if (strcmp(temp, "SCOUNT") == 0){
genedata[i].scount = atoi(line);
}
i++;
fscanf (dataPtr, "%s", temp);
if (strcmp(temp, "//") != 0){
fgets (line, SIZE, dataPtr);
}
} /*close while*/
if(( dataPtr = fopen( "records.dat", "w")) == NULL){
printf("error");}
else{
for (j=1; j<=i; j++){
fwrite(&genedata, sizeof(struct data), j, dataPtr);
}
}
fclose (dataPtr);
} /*close else*/
return 0;
}