0
I am trying to open a text file in a function int abreArquivoEntrada
, and for this I am sending as parameter the type pointer FILE
and the one vector of char
containing the file name, within the function I use the function of fopen
, however when I print the file pointer after running the function, it has not changed.
Grateful from now on.
#include <stdio.h>
#include <stdlib.h>
struct PESSOA{
char nome[50];
int idade;
float altura;
};
void leNomeArquivoEntrada(char* S1){
printf("Nome do arquivo: ");
scanf("%s",S1);
}
int abreArquivoEntrada(FILE *Arq , char* S1){
Arq = fopen(S1,"r");
printf("Na funcao %d \n", Arq);
if(Arq == NULL)
return 0;
else
return 1;
}
void fechaArquivo(FILE *Arq){
fclose(Arq);
}
int main()
{
char S1[50], inf[50];
struct PESSOA Povo[10], P;
FILE *Arq;
int i;
leNomeArquivoEntrada(S1);
printf("Na main antes da bertura %d \n", Arq);
if(abreArquivoEntrada(Arq, S1) == 1){
printf("Na main %d \n", Arq);
fscanf(Arq,"%s", &P.nome);
fscanf(Arq,"%d", &P.idade);
fscanf(Arq,"%f", &P.altura);
printf("%s \n", P.nome);
printf("%d \n", P.idade);
printf("%f \n", P.altura);
fechaArquivo(Arq);
}
else printf("Erro na abertura do arquivo");
return 0;
}
I could not understand what you want to do. You would like to display the contents of the file in the function
leNomeArquivoEntrada()
, would be this?– gato