Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions