During an assignment in school I came across this phenomenon which I cannot understand.
My task was to read two files and check wether they are exactly the same. I made two text files which contained the exact same line:
"Hello world"
I decided to check the text char by char. at first I wrote the following code:
EDIT: Due to many requests i've re-written the entire code to be displayed here:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
    char c1, c2;
    int ans = 1;
    FILE *f1 = fopen("text1.txt","rt");
    FILE *f2 = fopen("text2.txt","rt");
    for (fscanf(f1, "%c", &c1), fscanf(f2, "%c", &c2); 
        !feof(f1) && !feof(f2) && ans; 
        fscanf(f1, "%c", &c1), fscanf(f2, "%c", &c2))
    { // Check Data:
    if (c1 != c2) ans = 0; 
    printf("%c %c\n",c1,c2); // Print side by side check
    } // Check Tail:
    if (!feof(f1)) ans=0;
    if (!feof(f2)) ans=0;
    if (ans) printf("File 1 == File 2");
    else printf("File 1 != File 2");
    return 0;
}
but for some reason the code entered 'H' into c1 and 'e' into c2. Why does it work like that?
EDIT: i cannot seem to replicate the problem (this happened to me during a test i took in the university, thus i cannot access the original code anymore. the university is using an outdated Microsoft Visual Studio 2012 while i code using the 2015express version/netbeans)
 
    