Question: I keep recieving a Segmentation fault (core dumped) when I run the c program. What is causing the issue and how can I fix it?

I keep recieving a Segmentation fault (core dumped) when I run the c program. What is causing the issue and how can I fix it?

#include #include

int main() { FILE *fpt = fopen("test.txt", "r"); char str1[15], str2[15]; int read;

printf("Enter the search string: "); fgets(str1, 15, fpt);

while(fscanf(fpt, "%15s", str2) == 1) { read = strlen(str2); if(strncmp(str1, str2, read)==0) { printf("Found: %s", str2); } } fclose(fpt); fgets(str1, 15, fpt); }

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!