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
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
Get step-by-step solutions from verified subject matter experts
