Thread: moving the pointer

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    1

    moving the pointer

    well i am a rookie..i m a school student with a c++ project work to be done..so i basically have a tick tac toc game in mind..i m having one problem with that program..that is moving the pointer from one square to another to fill in the x and o's ..someone plss help

  2. #2
    Nasal Demon Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    179
    Please paste example code that will illustrate your problem.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Why should you even move the pointer? Use the array notation instead.
    Devoted my life to programming...

  4. #4
    printf("Hello Cboard\n"); codeprada's Avatar
    Join Date
    Jan 2011
    Location
    In a little room at the back of your brain
    Posts
    68
    if it's an array then
    Code:
    #include <stdio.h>
    
    int main() {
        char board[9] = { 'X', 'X', 'O', 'O', 'O', 'X', '0', 'X', '0' };
        char *pboard = &board[0];
        for ( ; pboard != &board[8]; pboard++ ) {
              printf("%c\n", *pboard);
        }
        return 0;
    }

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    You mean:

    Code:
    #include <stdio.h>
    
    int main() {
        char board[9] = { 'X', 'X', 'O', 'O', 'O', 'X', '0', 'X', '0' };
        char *pboard = &board[0];
        for ( ; pboard != &board[9]; pboard++ ) {
              printf("%c\n", *pboard);
        }
        return 0;
    }
    Devoted my life to programming...

  6. #6
    printf("Hello Cboard\n"); codeprada's Avatar
    Join Date
    Jan 2011
    Location
    In a little room at the back of your brain
    Posts
    68
    Quote Originally Posted by Sipher View Post
    You mean:

    Code:
    #include <stdio.h>
    
    int main() {
        char board[9] = { 'X', 'X', 'O', 'O', 'O', 'X', '0', 'X', '0' };
        char *pboard = &board[0];
        for ( ; pboard != &board[9]; pboard++ ) {
              printf("%c\n", *pboard);
        }
        return 0;
    }
    xD my bad

    Code:
    for ( ; pboard <= &board[8]; pboard++ ) {
    doesn't really matter which method though. thanks for pointing it out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers
    By MrMatt027 in forum C++ Programming
    Replies: 14
    Last Post: 12-10-2010, 04:32 PM
  2. Replies: 1
    Last Post: 03-24-2008, 10:16 AM
  3. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM