I have a similar program that'll read an entire text file no problem. But maybe it's how i have my fscanf here? First time I've run into something like this tbh. Basically I'm storing the first string in a file into a variable, and trying to use that to go through each line in a second file to see if the string is there.
#define MAX_LENGTH 500
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main() {
char string1[MAX_LENGTH]; //this will each string from my first file to compare every string in the second file
char string2[MAX_LENGTH];
int result;
FILE *fp1;
FILE *fp2;
fp1 = fopen("C:/textfile1.txt", "r");
fp2 = fopen("C:/textfile2.txt", "r");
if (fp1 == NULL || fp2 == NULL) {
printf("FILE cannot be opened... exiting...");
exit(1);
}
//while (1) {
while(! feof(fp1)) {
fscanf(fp1, "%[^\n]s", string1);
while (! feof(fp2)) {
fscanf(fp2, "%[^\n]s", string2);
result = strcmp(string1, string2);
if (result == 1) {
printf("%s has been ADDED...\n", string1);
}
}
}
while(! feof(fp2)) {
fscanf(fp2, "%[^\n]s", string1);
while (!feof(fp1)) {
fscanf(fp1, "%[^\n]s", string1);
result = strcmp(string2, string1);
if (result == 1) {
printf("%s has been REMOVED...\n", string2);
}
}
}
//}
getchar();
getchar();
return 0;
}