Platform: ANSI C, RTOS
Hi,
I am trying to fread a database from a text file, and assign the database directly to the public structure below. In the text file first 20 chars is for SKU next 35 chars for product and last 5 chars for quantity.
// Structure for Database
typedef struct _database
{
char SKU[20];
char product[35];
char quantity[5];
}
db;
My code to assign address of the first char of database to the begining address of structure.
...
db *database;
database = (char *)malloc(sizeof(db)); //or malloc(sizeof(char)*60);
handle = x_fopen("/flash/database.txt","r");
x_fread(handle,database,sizeof(db));
printf("SKU : %s\n", database->SKU);
printf("PRODUCT : %s\n", database->product);
printf("QUANTITY : %s\n", database->quantity);
What I get for database->SKU is the whole line with 60 chars strlen(?).
database->product starts from the right char (26) but goes to the end.
database->quantity start from right address as others goes till the end.
I need to split the first 25 char and next 35 chars and last 5 chars. Can I do it without 3 fread command (fread(first 25) fread(next 35) fread(last5))?
Thank you.