reading instructions

This is a discussion on reading instructions within the C Programming forums, part of the General Programming Boards category; i want to write a program that reads and convert instructions into some numbers like for example add 1,2 subtract ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    37

    reading instructions

    i want to write a program that reads and convert instructions into some numbers like for example

    add 1,2
    subtract 4,2

    expected output is
    000100010002
    &
    000200040002

    where first 4 digits means instruction number
    next 4 is the first number
    last 4 is the 2nd number

    what function can i use to read the input

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Make a list of the instructions you want to support and their values.

    You read in the instruction and break it up into the three parts:
    the instruction, the first number, and the second number.

    Then you can use something akin to
    Code:
    printf("%04d%04d%04d", value_of_instruction, first_number, second_number);

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    37
    yes i know that
    but how do i break it up?
    should i use sscanf?

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Thats one possiblity. You also have two delimiters (the space and the comma) so you could also use strtok()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2009, 02:14 AM
  2. Replies: 7
    Last Post: 02-02-2009, 06:27 AM
  3. Resetting a ifstream object after reading the whole file
    By Zeeshan in forum C++ Programming
    Replies: 5
    Last Post: 03-31-2008, 08:03 AM
  4. Replies: 2
    Last Post: 01-28-2008, 02:07 AM
  5. help with reading from stream
    By movl0x1 in forum C Programming
    Replies: 7
    Last Post: 05-31-2007, 10:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21