#include <stdio.h>
#include <stdbool.h>
int main() {
    char sim1, sim2, n;
    bool ni = false;
//открываем текстовые файлы//
    FILE *txt1;
    txt1=fopen("txt.txt","r");
    FILE *txt2;
    txt2=fopen("txt2.txt","r");
    FILE *txt3;
    txt3=fopen("txt3.txt","w");
//тестим на предмет их наличия//
    if (!txt1 || !txt2 == NULL) {
        printf (  "I can't open a file for reading \n" );
        return 1;
    }
    if(!txt3==NULL) {
        printf( "I can't open a file for writing \n");
        return 1;
    }
    printf ( "txt1 and txt2 files are open \n");
    // посимвольно сравниваем txt1 и txt2//
    while(txt1 && txt2) {
        txt1=fgets(sim1);
        txt2=fgets(sim2);
        if(sim1 == sim2)
            fputc(sim1,txt3);
        else
            ni = true;
    }
    if(ni==false) {
        // сообщение о успехе
        printf (  "The file contents are identical \n" );
    } else {
        // Если посимвольное сравнение не увенчалось успехом
        printf (  "The contents of the files are not identical \n" );
    }
    // закрываем файлы
    fclose(txt1);
    fclose(txt2);
    fclose(txt3);
    printf ( "End of program" );
    return 0;
}char *fgets(char *s, int size, FILE *stream);sim1=fgetc(txt1);while(!feof(txt1) && !feof(txt2)) { ... }int isequal=1;
while(!feof(txt1) && !feof(txt2)) {
  char buf1[1024];
  char buf2[1024];
  int readsize1 = fread(buf1, 1, 1024, txt1);
  int readsize2 = fread(buf2, 1, 1024, txt2);
  if (readsize1 != readsize2) {
    isequal=0;
    break;
  } else {
    if (memcmp(buf1, buf2, readsize1)) {
      isequal=0;
      break;
  }
}
if(isequal) {
  // одинаковы
} else {
  // отличаются
} 
  
  #include <stdio.h>
#include <stdbool.h>
int main() {
    char sim1, sim2;
    bool ni = false;
    //открываем текстовые файлы//
    FILE *txt1 = fopen("txt1.txt", "rb");
    FILE *txt2 = fopen("txt2.txt", "rb");
    FILE *txt3 = fopen("txt3.txt", "wb");
    //тестим на предмет их наличия//
    if (txt1 == NULL || txt2 == NULL) {
        printf (  "I can't open a file for reading \n" );
        return 1;
    }
    if(txt3 == NULL) {
        printf( "I can't open a file for writing \n");
        return 1;
    }
    printf( "txt1 and txt2 files are open \n");
    // посимвольно сравниваем txt1 и txt2//
    while(!feof(txt1) && !feof(txt2)) {
        sim1 = fgetc(txt1);
        sim2 = fgetc(txt2);
        if(sim1 == sim2 && !feof(txt1) && !feof(txt2))
            fputc(sim1, txt3);
        else if(sim1 != sim2 || !feof(txt1) || !feof(txt2))
            ni = true;
    }
    if(!ni && feof(txt1) && feof(txt2)) {
        // сообщение о успехе
        printf ("The file contents are identical \n" );
    } else {
        // Если посимвольное сравнение не увенчалось успехом
        printf ("The contents of the files are not identical \n" );
    }
    // закрываем файлы
    fclose(txt1);
    fclose(txt2);
    fclose(txt3);
    printf ( "End of program" );
    return 0;
}