Thread: Would you help me understand this code?

  1. #16
    Registered User
    Join Date
    Oct 2007
    Posts
    242
    Yeah, but why 1? why minus 1 and not minus 3234342? (lol)
    and why does it ask if ej/ei is bigger or smaller than 0 or 2?
    and more one thing:
    Code:
        int board[3][3], *p = (int*)board;
        int i, j, c, x, ei, ej;
        
        //initialization
        for(i = 0, c = 8; i < 3; i++)
            for(j = 0; j < 3; j++, c--)
                board[i][j] = c;
        board[ei = 2][ej = 2] = 0;
    what does these lines do?
    Last edited by eXeCuTeR; 10-26-2007 at 08:52 PM.

  2. #17
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    not to sound like a jerk, but do you even know what a for loop is?

  3. #18
    Registered User
    Join Date
    Oct 2007
    Posts
    242
    ...
    To repeat something a couple times (you define how many times it repeats)
    :O

    Well,
    I will express my question differently:
    What are these lines for? why do I need them for my code?
    and what do they do? i know that all the "[3][3] boards now equals to c what what is c and what does it equal to? and why board[ei = 2][ej = 2] = 0? wtf? and what does ei and ej equals to?
    and why *p = (int*)board? it means that *p stores the address of board? how come? usually when we wanna store data we do p = &variable_name; why is it different here?
    Last edited by eXeCuTeR; 10-26-2007 at 09:14 PM.

  4. #19
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    >What are these lines for? why do I need them for my code?
    to initialize the array.
    >and what do they do? i know that all the "[3][3] boards now eqauls to c what what is c?
    c is an iterator. a counter number variable thing.
    > and why board[ei = 2][ej = 2] = 0? wtf?
    sets the starting pos.
    > and why *p = (int*)board? it means that *p stores the address of board? how come?
    because the author wanted to check for a win in an inane way.

  5. #20
    Registered User
    Join Date
    Oct 2007
    Posts
    242
    thanks but,
    1.alright, ok.
    2. what is an iteratior i don't understand.
    3. starting pos? what's a pos?
    4. to check a victory in an inane way? what?

    and btw
    why does the board[ei = 2][ej = 2] equals to 0?
    and what are the ei and ej?

  6. #21
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    for (i=0;i<5;i++)

    i is an iterator.

    pos = position.

    the author decided to iterate through the array as a one dimensional array instead of a two dimensional array.
    Last edited by robwhit; 10-26-2007 at 09:32 PM.

  7. #22
    Registered User
    Join Date
    Oct 2006
    Location
    Omaha, Nebraska
    Posts
    116
    lets try this:
    what are you trying to do, not with this code, but ultimately what are you trying to accomplish by understanding what this piece of code does?
    its not making sense to me as to why you're even inquiring about it when clearly you havent even attempted to learn the fundamentals.
    >why do i need them for my code
    what code and why are you writing code with this if you have to ask what it is that every line does?
    again, not to be a jerk or anything im just confused as to why you're asking about it.
    if we knew more about where you want to get to we'd be able to help you out more.

  8. #23
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    >Yeah, but why 1? why minus 1 and not minus 3234342? (lol)
    because you can only move only space at a time.
    >and why does it ask if ej/ei is bigger or smaller than 0 or 2?
    it's range checking. for the array.
    this:
    Code:
    board[ei = 2][ej = 2] = 0;
    does the same thing as this:
    Code:
    ei = 2;
    ej = 2;
    board[2][2] = 0;

  9. #24
    Registered User
    Join Date
    Oct 2007
    Posts
    242
    why does board[2][2] equals to 0?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM