1
I’m trying to read a file on. c, I can read everything right there but in the variable it returns me a whole content and a " n" that harms the rest of my code. Below is the section that performs the txt reading for you to analyze.
char * info_conta(char *cpf,int line)
{
//Declaro variaveis para ler o arquivo
char contacaminho[80]="contas/",linha[80], cpf2[14];
strcpy(cpf2,cpf);
int id = 1;
//Concatenho com a pasta e o numero do cpf para carregar os dados
//strcpy(contacaminho, "contas/");
strcat(contacaminho, cpf2);
strcat(contacaminho,".dat");
//Crio uma variavel do tipo FILE para ler o arquivo
FILE *arquivo = fopen(contacaminho,"r");
//Crio um laço de repetição para ler o arquivo
while(fgets(linha, 80, arquivo) != NULL)
{
if(id == line)
{
// Paro o laço de repetição e mantenho o valor da variavel.
break;
}
id++; // Aumento o valor da chave identificadora em + 1;
}
fclose(arquivo); // Fecho o arquivo
return linha; // retorno as infromações
}
This question is about
objective-c
orc
?– Vinícius Gobbo A. de Oliveira
I put the tag Objective C since you quote in the title, but make sure it has something to do with this language?
– Maniero
"It harms my whole code" can mean a lot. Be clearer: what do you expect to happen? What’s going on?
– Vinícius Gobbo A. de Oliveira
.c is the extension saved, on the "harm" is the following I hope to concatenate the value ai as it comes with n it does not show the other concatenated data because I am using the system() command and give a title for example.
– Hiago Souza
Duplicate of Removing the " n" from a string read using fgets().
– pmg
Sorry more has nothing to do pmg, the guy is using a fgets I’m reading a text file.
– Hiago Souza