I'm doing a function that consists of reading elements of a file I wrote and priting them. The problem is, it seems the first number for every line of the text file is being read and printed in a way I don't understand on how it arrived. It's mostly numbers from 90-110 and zeros.
I tried chaging the variable to chars and floats, but neither worked.
void imprimir_tabela(){
FILE *tabela = fopen("tabela.txt", "r");
if(tabela == NULL){
printf("TABELA INVALIDA OU NAO ACHADA");
printf("erro 404");
exit(404);
}
int numero_atomico;
char abreviacao;
char nome[20];
float massa_atomica;
int grupo;
int periodo;
while(!feof(tabela))
{
fscanf(tabela, "%d %s %s %f %d %d", &numero_atomico, &abreviacao, &nome, &massa_atomica, &grupo, &periodo);
printf("%d - %s - %s - Massa atomica: %0.3f - Grupo: %d - Periodo: %d\n", numero_atomico, &abreviacao, &nome, massa_atomica, grupo, periodo);
}
rewind(tabela);
return 0;
Sample lines of the text file
1 H Hidrogenio 1.008 1 1
2 He Helio 4.003 18 1
3 Li Litio 6.941 1 2