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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started