I read the txt file, but it shows blank

Asked

Viewed 30 times

0

I want to read a truth table from a txt file but it does not show anything of the file, nor the table numbers, nor any other character I have put to test

#include<iostream>
#include<STDIO.H>
using namespace std;

int main() {
    int valor;

    FILE *arquivo;

    arquivo =  fopen("tbV.txt","rt");
   
    fscanf(arquivo, "%d", &valor);
    fprintf ("%d", valor);

   if(arquivo==NULL){
    cout<<"Não foi possivel abrir o arquivo"<<endl;

   }

   fclose(arquivo);
}
  • 2

    Post at least one sample line of your file. It would be convenient if you were able to test whether or not to open the file before to use it and not to test after trying to use it.

  • Post the test file and the expected result. Wrote a program in C actually...

1 answer

0


Validate if the file has been opened and use absolute paths or related to the implementation directory.

 if ((arquivo = fopen("C:\\program.txt","r")) == NULL){
       printf("Erro ao abrir arquivo");
       exit(1);
 }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.