a Movement doubt in an array

This is a discussion on a Movement doubt in an array within the C Programming forums, part of the General Programming Boards category; Hi, I would like to know if someone knows how can i move through an array by using the arrow ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    66

    Unhappy a Movement doubt in an array

    Hi, I would like to know if someone knows how can i move through an array by using the arrow keys, for example my array is
    Code:
    a{2, 3, 5, 64, 7, 34}
    and the display is 2

    them when the user press the right aroow key it automaticaly moves to the second element of the list (so I can modify it if I want) and it prints 3

    right arrow key again and it prints 5, then, left arrow and it prints 3, etc

    i have been told that I should use the ASCII code and getchar(), however i really have no Idea how to make it work.

    thx

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    277
    I think that using a ASC table you can get the code of the imput you get from the keyboard using something like a getchar then all you need is a switch. Meybe there are more intelligent or easier ways, but I was the first thing that came up to my mind. Go google and look for a ASCII Table

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    I believe you're looking for getch(). getch() will return a numerical value based on the keyboard key that was hit. I believe, however, that with the arrow keys, it returns two values.

    So, if you press an arrow key, I believe the first call to getch() will return a 224, whereas the second call returns the numerical value of the arrow key.....you'll have to do some testing of this on your own, something like so:

    Code:
    int key=getch();
    if(key==224)
    {
        key=getch();
    // process the arrow keys here....and some other buttons
    }
    else
    {
    // process the other keys here
    }
    I can't remember exactly if 224 is actually the number that it returns for the arrow keys....so don't quote on me on that, but at least test it out.

    -edit-
    forgot about the FAQ...it's 224 not 227. Sorry bout that, haven't used getch in ages.
    Last edited by jverkoey; 02-03-2005 at 09:05 PM.

  4. #4
    Registered User Sake's Avatar
    Join Date
    Jan 2005
    Posts
    89
    The FAQ has a pretty good article on your problem here.
    Kampai!

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    66
    Ok i'll read the FAQ and also try the getch, thanks.

    Any other Ideas will be also really apreciated

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 11:33 AM
  2. Creating a menu that reads input via an array?
    By Nalif in forum C Programming
    Replies: 6
    Last Post: 09-29-2006, 10:21 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM
  5. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 01:44 AM

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