Peter Kwan
asked on
URGENT! What is wrong with this code?
I am doing a project and the following is one part of my code.
#include <stdio.h>
#include <stdlib.h>
#define NO_VOTERS 2977
#define NO_MOVIES 1627
struct Person {
short id;
/* char zipcode[6]; */
short age;
char gender;
};
struct Movie {
/* char theatre_status[8];
char video_status[8]; */
short id;
short action;
short animation;
short art_foreign;
short classic;
short comedy;
short drama;
short family;
short horror;
short romance;
short thriller;
};
struct Vote {
short person_id;
short movie_id[NO_MOVIES];
float score[NO_MOVIES];
};
int main(int argc, char** argv) {
FILE *infile1, *infile2, *infile3, *outfile;
struct Person voter[NO_VOTERS];
struct Movie movie[NO_MOVIES];
struct Vote vote[NO_VOTERS];
short last_read_person_id, person_id, movie_id;
float score;
short notfound;
short movietype[10];
int i, j, k, m;
float t;
fprintf(stderr, "Opening file...\n");
if ((infile1=fopen("person_si mplified.t xt", "r"))==NULL) {
fprintf(stderr, "Error opening file: person_simplified.txt\n");
exit(-1);
} if ((infile2=fopen("movie_sim plified.tx t", "r"))==NULL) {
fprintf(stderr, "Error opening file: movie.txt\n");
exit(-1);
}
if ((infile3=fopen("vote1_sim plified.tx t", "r"))==NULL) {
fprintf(stderr, "Error opening file: vote1.txt\n");
exit(-1);
}
if ((outfile=fopen("vote.nomi nal.arff", "w"))==NULL) {
fprintf(stderr, "Error opening file: vote1.txt\n");
exit(-1);
}
fprintf(stdout, "Initialization...\n");
for (i=0; i<NO_VOTERS; i++) {
for (j=0; j<NO_MOVIES; j++) {
vote[i].movie_id[j]=-1;
vote[i].score[j]=-1;
}
}
return 0;
}
I am getting "Segmentation fault" when getting into the for loop. Can someone helps me?
#include <stdio.h>
#include <stdlib.h>
#define NO_VOTERS 2977
#define NO_MOVIES 1627
struct Person {
short id;
/* char zipcode[6]; */
short age;
char gender;
};
struct Movie {
/* char theatre_status[8];
char video_status[8]; */
short id;
short action;
short animation;
short art_foreign;
short classic;
short comedy;
short drama;
short family;
short horror;
short romance;
short thriller;
};
struct Vote {
short person_id;
short movie_id[NO_MOVIES];
float score[NO_MOVIES];
};
int main(int argc, char** argv) {
FILE *infile1, *infile2, *infile3, *outfile;
struct Person voter[NO_VOTERS];
struct Movie movie[NO_MOVIES];
struct Vote vote[NO_VOTERS];
short last_read_person_id, person_id, movie_id;
float score;
short notfound;
short movietype[10];
int i, j, k, m;
float t;
fprintf(stderr, "Opening file...\n");
if ((infile1=fopen("person_si
fprintf(stderr, "Error opening file: person_simplified.txt\n");
exit(-1);
} if ((infile2=fopen("movie_sim
fprintf(stderr, "Error opening file: movie.txt\n");
exit(-1);
}
if ((infile3=fopen("vote1_sim
fprintf(stderr, "Error opening file: vote1.txt\n");
exit(-1);
}
if ((outfile=fopen("vote.nomi
fprintf(stderr, "Error opening file: vote1.txt\n");
exit(-1);
}
fprintf(stdout, "Initialization...\n");
for (i=0; i<NO_VOTERS; i++) {
for (j=0; j<NO_MOVIES; j++) {
vote[i].movie_id[j]=-1;
vote[i].score[j]=-1;
}
}
return 0;
}
I am getting "Segmentation fault" when getting into the for loop. Can someone helps me?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER