Thread: Wrap around in array

  1. #16
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    HAPPY BIRTHDAY TATER!
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  2. #17
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by AndrewHunter View Post
    HAPPY BIRTHDAY TATER!
    BLUSH!

    Thanks!

  3. #18
    Registered User
    Join Date
    Jul 2011
    Posts
    44
    Sorry guys but that isn t even working the output I'll get is this :
    3 same wrong
    4
    1
    3
    3
    5
    2
    32767
    10
    3

    And I expect only this :
    3 same wrong

  4. #19
    Registered User
    Join Date
    Jul 2011
    Posts
    44
    I'm going with birthdayguys example, it looks so simple it must work !

  5. #20
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by lamko View Post
    Sorry guys but that isn t even working the output I'll get is this :
    3 same wrong
    4
    1
    3
    3
    5
    2
    32767
    10
    3

    And I expect only this :
    3 same wrong
    Post the exact code that produced that result please...

  6. #21
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Mull over tabstop's post instead of jumping around and don't omit his suggestion in the printf() part:
    Code:
    printf ( "%d same wrong  \n", board[i%9] );
    Last edited by itCbitC; 08-17-2011 at 12:00 PM.

  7. #22
    Registered User
    Join Date
    Jul 2011
    Posts
    44
    Your right :

    Code:
    #include <stdio.h>
    
    int main ( void )
    {
      int board[] = {9, 8, 6, 3, 4, 1, 3, 5, 2};
      int pos = 3;
    
      int i;
        for ( i = pos; i < pos+9; i++ )
            if (pos == i % 9)
                continue;
            else if (board[i % 9] == board[pos])
                printf ( "%d same wrong  \n", board[i % 9] );
                //return true to use in other part of the program
    return 0;
    }
    This code is working like expected !
    I made some errors because I was working to fast I'm only a newbie and need sometime to understand the code preferabel, I use a debugger just to see the values.

  8. #23
    Registered User
    Join Date
    Jul 2011
    Posts
    44
    The best thing I learned from you guys is how to use modulo in a for loop and why you never use i and only i % 9

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. It's a wrap!
    By Salem in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-10-2007, 02:00 PM
  2. Word wrap
    By Orrill in forum C++ Programming
    Replies: 6
    Last Post: 10-14-2005, 02:00 PM
  3. Word Wrap
    By sethjackson in forum Windows Programming
    Replies: 4
    Last Post: 09-21-2005, 04:35 PM
  4. Word Wrap
    By osal in forum Windows Programming
    Replies: 4
    Last Post: 07-02-2004, 11:16 AM
  5. word wrap
    By max in forum C Programming
    Replies: 6
    Last Post: 08-24-2002, 10:44 AM