Thread: Move A character in 2D array

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    23

    Exclamation Move A character in 2D array

    Hello
    I want to move a character in a 2D array
    This Character should move vertically in a 2D Array
    To exemplify it for Exam in Snake Game A character automatically moves
    Please Write a example code that works
    Thanks A lot

  2. #2
    Registered User
    Join Date
    Jan 2015
    Posts
    23
    Please Help me Fast

    (Sorry For spamming)

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I suggest that you write a program that declares and populates a small 2D array, perhaps printing it. This will show us a skeleton of the program that you can start from, as well as show us a set of test input. Then, show us your expected output. From there, we can suggest how you can come up with a solution to write code that will arrive at your expected output.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Jan 2015
    Posts
    23
    Can you please Write An example For me?

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Sure. Here's an example of what I described in post #3, with a 1D array of char:
    Code:
    #include <stdio.h>
    
    #define N 10
    
    int main(void)
    {
        char characters[N] = "abcdefghi";
        printf("%s\n", characters);
        /* code to move a character */
        /* ... */
        printf("%s\n", characters);
        return 0;
    }
    I do not know what the expected output will be though, since it is unclear to me what exactly "move a character" means. Of course, when you follow my suggestions in post #3 for your 2D array, your example could help to explain what it means.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-08-2014, 08:52 AM
  2. Move Character while in other loop
    By binks in forum C Programming
    Replies: 26
    Last Post: 04-28-2011, 03:27 PM
  3. Replies: 12
    Last Post: 12-06-2005, 08:30 PM
  4. how to move character in maze
    By ccwash in forum C++ Programming
    Replies: 4
    Last Post: 11-06-2005, 11:36 PM
  5. Making a character MOVE!
    By unknownUser in forum Linux Programming
    Replies: 5
    Last Post: 05-19-2002, 04:42 PM