I have a dados.txt
file with (fictitious) CPFs in the following format:
382031758-71
647900189-01
460754503-73
696170135-72
And so on, with a total of 500 cpfs. I'm trying to read each one and put char cpf[12]
(because each one has 12 characters counting -
), however when printing three strange characters type @ýý
int main(){
//abre o arquivo em modo leitura
FILE *dados = fopen("dados.txt", "r");
char cpf[12];
fseek(dados, 0, SEEK_SET); //vai para o inicio do arquivo
//fgets(cpf, 100, dados); //pega 12 caracteres
for(int i = 0; i < 12; i++){
cpf[i] = fgetc(dados);
}
printf("%s\n", cpf);
fclose(dados);
}
I also tried with fscanf(dados, "%s\n", cpf);
but it was the same. So I'd like to understand how to read this data in this way. I want to store in a variable because I need to use this to test a hash function afterwards.