Question: I am receiving a Segmentation Fault (core dumped) error. What am I doing wrong? #include #include #include #define MAX 300 int main() { FILE *file;

I am receiving a Segmentation Fault (core dumped) error. What am I doing wrong?

#include #include #include #define MAX 300

int main() {

FILE *file; char arr[MAX]; char *ptr[MAX] = {NULL}; int size; int i=0; int j; *file = *fopen("/home/seed/Documents/Heier_Sidney_HW01/ints_text.txt", "r"); if(file == NULL) { printf("cannot open file"); exit(1); }

while (i < MAX && fgets(arr, sizeof(arr), file)!= NULL){ size_t len = strlen(arr); if (arr[len-1] == ' ') arr[--len] = 0; else { fprintf (stderr, "error "); exit (EXIT_FAILURE); } ptr[i] = strdup(arr); i++; }

for (j = 249; j < 248; j--) { printf ("%s ", ptr[j]); free(ptr[j]); }

fclose(file);

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!