RWalib C Array Library User Guide > Relational Operations > alibFirstDiff
  

alibFirstDiff
Locates the first difference between an array and a second array or scalar.
Prototype
wvlong alibFirstDiffl( wvlong m, wvlong *b, wvlong n, wvlong *e )
Parameters
m — (Input) The number of elements in the first operand.
*b — (Input) The pointer to the first operand.
n — (Input) The number of elements in the second operand. n must equal 1 or m.
*e — (Input) The pointer to the second operand.
Return value
If n=1, this value is the first index where array b does not equal scalar e. Otherwise, it is the first index where array b does not equal array e. If no such indices exist, i.e., no differences are found, –1 is returned.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
   /* make up some data for the examples */
   wvlong b0[9]={2,2,2,6,0,5,1,4,3}, b1[9]={2,2,2,6,0,5,3,1,1}, b2=2, b;
   printf( "\n\n print arrays b0 and b1 as (3,3) matrices" );
      alibinit( NULL, NULL, NULL, NULL );
      alibPrintArrayl( 1, 1, 3, 3, b0, NULL );
      alibPrintArrayl( 1, 1, 3, 3, b1, NULL );
   printf( "\n\n find the first index where b0 does not equal b2=2 \n\n" );
      b = alibFirstDiffl( 9, b0, 1, &b2 );
      printf( "%40lld\n", b );
   printf( "\n\n find the first index where b0 and b1 are not equal \n\n" );
      b = alibFirstDiffl( 9, b0, 9, b1 );
      printf( "%40lld\n", b );
}
 
Output:
 
 print arrays b0 and b1 as (3,3) matrices
 
                    2                    2                    2
                    6                    0                    5
                    1                    4                    3
 
                    2                    2                    2
                    6                    0                    5
                    3                    1                    1
 
 find the first index where b0 does not equal b2=2 
 
                                       3
 
 find the first index where b0 and b1 are not equal 
 
                                       6

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.