Windows 8 MinGW misleading programme



  • When using the following code:

    #include <stdio.h>
    #include <stdlib.h>
    int main ( int argc, char *argv[] ) {
    
    FILE *blabla = fopen("blabla.txt","w");
    if (blabla == NULL){
        printf("aaaa\n");
        exit(1);
    }
    if (fclose(blabla) == EOF){
        printf("bbbb\n");
        exit(1);
    }
    
    
    
    FILE *in_file = fopen ( "log.txt", "r" );
    
    printf("some phrase\n");
    
    fclose ( in_file );
    
    return 0;
    

    }

    The program begins to behave incorrect after the approximately 40th challenge:
    введите сюда описание изображения

    As can be seen above, the program duplicates the invitations to the command line. Sometimes there are vague letters and numbers instead of duplicate invitations. Sometimes the duplicates are visible after the second to third launch.

    But if you're to corroborate the instructions of the first file descriptor:

    #include <stdio.h>
    #include <stdlib.h>
    int main ( int argc, char *argv[] ) {

    //FILE *blabla = fopen("blabla.txt","w");
    //if (blabla == NULL){
    //  printf("aaaa\n");
    //  exit(1);
    //}
    //if (fclose(blabla) == EOF){
    //  printf("bbbb\n");
    //  exit(1);
    //}
    
    
    
    FILE *in_file = fopen ( "log.txt", "r" );
    
    printf("some phrase\n");
    
    fclose ( in_file );
    
    return 0;
    

    }

    There is no problem. I'm using MinGW GCC version 4.8.1 on Windows 8. The programme was going to the team:

    gcc -std=gnu11 -o main2 main2.c

    Thank you for your support.



  • You don't have to check that fopen("blabla.txt","w") Not back. NULL

    If that happens, NULLfclose
    This leads to an uncertain behaviour, and the program is probably falling.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2