I keep recieving a Segmentation fault (core dumped) when I runthe c program. What is causing the issue and how can I fix it?
#include<stdio.h>
#include<string.h>
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);
}
Expert Answer
An answer will be send to you shortly. . . . .