Home > Back-end >  strange behavior when trying to read a file
strange behavior when trying to read a file

Time:01-06

if(argc==1){    
    } else if(argc==2){
        FILE *f=fopen( argv[1],"r");

        if(!(f==NULL)){
            jogada='x';
            while(countblank(board)!=0 || (checkmoves(board,jogada)>0)){
                fscanf(f,"%d%c",&fline,&fcol_char);
                fcol=fcol_char-'A';
                fline--;

                play(board,fline,fcol,jogada);
                jogada=opcolor(jogada);
                if(fgetc(f)==EOF){
                    break;
                }
            }
            fclose(f);
            print_board(board);
        }
        else{
        printf("\nFicheiro não foi lido\n");
        }
    }

I use gcc and when I do ./othello_func jogadas.txt it is supposed to read the plays in the file jogadas.txt that has something like

4C
3E

but when I do ./othello_func jogadas.txt it just shows me the message from the else.

CodePudding user response:

when I do ./othello_func jogadas.txt it just shows me the message from the else.

  • The program "othello_func" and "jogadas.txt" are not in the same folder. OP reports they are but may be mistaken about which folder code is run from.

OR

  • The file "jogadas.txt" is not available for reading - perhaps being used by another program like an editor.
  •  Tags:  
  • Related