I have two files blacklist.txt and email.txt. The blacklist.txt contains some domain names. The email.txt also contains a few domain names. I have to compare both files and find the domain names of blacklist.txt into email.txt using the strstr()
function. Following is the code I have written. The problem with this code is it returns me the output NULL
instead of the matched text/domain name.
#include <stdio.h>
#include <string.h>
#define MAXCHAR 1000
int main() {
FILE *fp, *fp1;
char str[MAXCHAR];
char str2[MAXCHAR];
char *result;
fp = fopen("blacklist.txt", "r");
fp1 = fopen("email.txt", "r");
if (fp == NULL || fp1 == NULL) {
printf("\n Cannot open one of the files %s %s \n", fp, fp1);
//return = 0;
if (fp != NULL) fclose(fp);
if (fp1 != NULL) fclose(fp1);
}
while (fgets(str, MAXCHAR, fp) != NULL || fgets(str2, MAXCHAR, fp1) != NULL)
//printf("%s, %s", str,str2);
fclose(fp);
fclose(fp1);
result = strstr(str, str2);
printf("The substring starting from the given string: %s", result);
return 0;
}