keep getting segmentation fault! arrrggghhhh!!!!!!!!!!
i have run the program multiple times, and have redone it four times. my buddy who's in the same class looked at it and said its similar to his, yet his works. this program is supposed to read file data and output it to a random access file.
Code:
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 500
struct data{
int id;
char title [SIZE];
char gene [SIZE];
char express [SIZE];
char chrom [SIZE];
int scount;
};
int main (){
int i;
int j;
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*/
for (j=1; j<=SIZE; j++){
fwrite(&genedata, sizeof(struct data), j, dataPtr);
}
fclose (dataPtr);
} /*close else*/
return 0;
}
an example of the input data can be found here: http://texas.eng.uiowa.edu:8088/bme/59_006/Hs.small
i greatly appreciate any help. thanks!
steve