Opening a file using fopen with same flag in C
问题 I could not understand the output of this code? int main() { FILE* f, *f1; f = fopen("mytext", "w"); if ((f1 = fopen("mytext", "w")) == 0) printf("unable\n"); fprintf(f, "hello\n"); fprintf(f1, "hi\n"); return 0; } OUTPUT IS hello in mytext file. Why is it not being written? "unable" is not printed to stdout. 回答1: You have 2 FILE* open to the same file, pointing at the beginning of the file, so one of the writes overwrites the other. Note also that FILE* are normally buffered, so these small