I am still new to C. I am reading from a file stock.dat:
I0001|Meat Pie|Yummy Beef in Gravy surrounded by pastry|3.50|50
I0002|Apple Pie|Delicious Stewed Apple in a Yummy Pastry envelope|3.00|20
I0003|Lemon Cheesecake|A delicious, 1/8 size slice of cheesecake|4.00|10
I0004|Lemon Meringue Pie|This pie has a tender pastry crust, a tangy lemon filling and a topping of soft, fluffy meringue.|3.00|20
I0005|Lemon Tart|A delicious lemon butter tart with a pastry base|3.75|12
I am tokenising it using the appropriate delimiters, then using memcpy to save to the struct. However, I am having problems with data.price.dollars, data.price.cents, and data.onHand.
I keep getting this warning: passing argument 1 of ‘memcpy’ makes pointer from integer without a cast [enabled by default]
data.id, data.name and data.desc does not display any warning.
I understand memcpy takes 2 pointers. But What I don't understand, is HOW i can make data.price.dollars/cents and data.onHand into a pointer? I have hit a wall here.
If I'm on the completely wrong track, I would really be thankful if someone could point me in the right direction.
This is my code:
Boolean loadStock(VmSystem * system, const char * fileName)
{
char *j; /*To convert Chars to numbers*/
char line[MAX_LEN_LINE];
FILE * fPointer; /*file pointer*/
Stock data;
List * list = system->itemList;
fPointer = fopen(fileName, "r"); /*open the file which is 2nd in the array of string which should be the data file, and "r" read it*/
while(!feof(fPointer)) /*file end of file*/
{
fgets(line, MAX_LEN_LINE, fPointer);
/*Tokenise*/
memcpy(data.id, strtok(line, STOCK_DELIM), ID_LEN+NULL_SPACE);
memcpy(data.name, strtok(NULL, STOCK_DELIM), NAME_LEN+NULL_SPACE);
memcpy(data.desc, strtok(NULL, STOCK_DELIM), DESC_LEN+NULL_SPACE);
memcpy(data.price->dollars, (int)strtol(strtok(NULL, "."), &j, 10), 2);
memcpy(data.price->cents, (int)strtol(strtok(NULL, "|"), &j, 10), 2);
memcpy(data->onHand, (int)strtol(strtok(NULL, " "), &j, 10), 2);
addToLinkedList(list, &data);
}
fclose(fPointer);
return FALSE;
}
typedef struct stock
{
char id[ID_LEN + NULL_SPACE];
char name[NAME_LEN + NULL_SPACE];
char desc[DESC_LEN + NULL_SPACE];
Price price;
unsigned onHand;
} Stock;