Thread: Input from terminal

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    Input from terminal

    Hey I wanted to know how to do an input form the terminal or like user stdin stuff to convert it into a hex. hopefully more
    basically i want it to be like

    >Input Hex: 123456

    unsigned char hex[3];
    .....convert?
    /*hex[0] = 12;
    hex[1] = 34;
    hex[2] =56;
    */ // Thats what the arrays would equal
    printf(" x02: x02:x02\n", hex[0],hex[1],hex[2]);
    i know itoa() might do it but that converts it into a int so iono if it would really work the same

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    One way would be to parse the input text into three int variables with scanf(); cast them to char while assigning them to each element of hex[].

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List from Standard Input
    By mercuryfrost in forum C Programming
    Replies: 14
    Last Post: 08-24-2009, 12:05 AM
  2. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 01:59 AM
  3. Console, Terminal and Terminal Emulator
    By lehe in forum C Programming
    Replies: 4
    Last Post: 02-15-2009, 09:59 PM
  4. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  5. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM