Comparing 2x2 arrays

This is a discussion on Comparing 2x2 arrays within the C Programming forums, part of the General Programming Boards category; so i have a series of 2x2 arrays that i want to compare edges for, example Code: char *tiles1[] = ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    2

    Comparing 2x2 arrays

    so i have a series of 2x2 arrays that i want to compare edges for, example

    Code:
    char *tiles1[] = {    "57",         "24",    "",    "84",         "57",    ""
    So i want to compare all of the sides until i find the 2 that match.
    What is the best way to go about doing this?

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    1,218
    You could look into using qsort(3) on your tiles. Even if you don't actually need to sort the tiles, one requirement of using that function is to design a COMPAR function which compares two elements of the type in question. In your case, two tiles should be considered equal if they have the same contents. In other words, you need to use strcmp pairwise on each item in the two tiles which are being compared.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    2
    i was thinking the easiest way to be to define a function that takes a tile and side number and returns the two numbers for that sidethat way you could loop over each edge in two tiles and compare each. But just wasnt sure the best way to go about it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Comparing 2 arrays
    By shel5210 in forum C Programming
    Replies: 2
    Last Post: 03-30-2010, 02:03 AM
  2. Comparing Arrays
    By cjohnman in forum C Programming
    Replies: 6
    Last Post: 04-24-2008, 04:24 PM
  3. Comparing Arrays
    By Raison in forum C++ Programming
    Replies: 10
    Last Post: 04-20-2004, 03:21 PM
  4. comparing arrays
    By dustyrain84 in forum C Programming
    Replies: 1
    Last Post: 01-21-2004, 05:52 PM
  5. Comparing Arrays
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-23-2001, 08:07 PM

Tags for this Thread


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