Thread: Receipt Machine in C

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    Receipt Machine in C

    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. =)
    Last edited by subwaybusker; 10-21-2008 at 12:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finite State Machine
    By ArlexBee-871RBO in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2008, 11:59 AM
  2. Replies: 4
    Last Post: 01-18-2008, 07:05 PM
  3. School Mini-Project on C/C++ (Need Your Help)..
    By EazTerence in forum C++ Programming
    Replies: 4
    Last Post: 09-08-2005, 01:08 AM
  4. Turing Machine
    By Brad C in forum Tech Board
    Replies: 2
    Last Post: 08-05-2005, 08:22 PM
  5. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 08:02 PM