+ 1

file handling with structures

how can I read the data into a .txt file in that form: "miles mi distance 1609.3 kilometres km distance 1000 metres m distance 1 kilograms kg weight 1 grams g weight 0.001 pounds lb weight 0.43592" I should store this data into an array of structures. Structures are in this form: typedef struct{ char name[L]; char abbreviation[L]; char type[L]; float conversion; } unit_t; I tried with fread() but it doesn't assign each string to the right field of the structures...how shold I do?

18th Dec 2019, 3:30 PM
Alessandro Palazzolo
Alessandro Palazzolo - avatar
1 ответ
+ 2
using fscanf is easier instead you do something like this while (!feof(fptr)){ fscanf("%s %s...", name, abbr..); }
19th Dec 2019, 2:35 AM
Shen Bapiro
Shen Bapiro - avatar