Wrap around in array

This is a discussion on Wrap around in array within the C Programming forums, part of the General Programming Boards category; HAPPY BIRTHDAY TATER!...

  1. #16
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    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,058
    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 01: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

Page 2 of 2 FirstFirst 12
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, 03:00 PM
  2. Word wrap
    By Orrill in forum C++ Programming
    Replies: 6
    Last Post: 10-14-2005, 03:00 PM
  3. Word Wrap
    By sethjackson in forum Windows Programming
    Replies: 4
    Last Post: 09-21-2005, 05:35 PM
  4. Word Wrap
    By osal in forum Windows Programming
    Replies: 4
    Last Post: 07-02-2004, 12:16 PM
  5. word wrap
    By max in forum C Programming
    Replies: 6
    Last Post: 08-24-2002, 11:44 AM

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