My receipt machine is given the standard input:
Code:
10/10/08 12:00
A1:2.31:1:p
2b:1.98:2:g
A1:2.31:2:P
where the first line is the time and the other lines are purchases (item name: price: quantity: type of tax)
I am supposed to intialize my arrays according to some format. I tried initializing my arrays (already declared as static) using:
Code:
void init(int id)
{
extern int cashier, num, quantity[NUM];
extern double price[NUM];
extern char tax_type[NUM], name[NUM][2], time[SIZE];
cashier = id;
strcpy(time, "00/00/00 00:00");
price[NUM] = 0;
tax_type[NUM] = 'U';
name [NUM] = '\0'; /*not sure how to intialize?*/
}
but then when i run the program, all the arrays are not intialized, instead it has a random value.
To purchase an item, I am supposed to use sscanf and getline (getline returns i) in a function to read the standard input and store it into static arrays. I am not sure how to relate sscanf and getline so I did something like this, but the first line didn't even work.
Code:
void purchase(void)
{
extern double price[NUM];
extern int quantity [NUM]; /* item quantity */
extern char tax_type[NUM]; /* tax on item */
extern char name [NUM][2]; /* item name */
extern char time [SIZE]; /* transaction time */
extern int num; /* number of distinct items purchased */
sscanf("%s", &time);
sscanf("%c:%f:%d:%c", &name[], &price, &quantity, &tax_type);
}
There are so many holes that i don't even know where to begin. I don't know how to store something in a two dimensional array for name.
I am a beginner to C, so any help would be appreciated. =)