LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ListRemoveDuplicates

I create a List using:
 
static ListType List_Session = 0;
 
List_Session = ListCreate (sizeof(char[20]));
 
Then I load this list with strings named as such:
 
SESSION T1
SESSION T3
SESSION Q1
SESSION Q1
 
Some of the names are duplicated which I am trying to use ListRemoveDuplicates (List_Session , 0); to remove them, but it is not working.  I am not sure, but I think the issue is with the compare fucntion that is being used.  0 just uses the memcmp() by default and I believe I need to pass CStringCompare() or similar funtion in its place, but I cannot figure out how and I cannot find an example of using ListRemoveDuplicates and CStringCompare
 
Any help on how to format and pass the correct arguements would be appreciated.
 
 
0 Kudos
Message 1 of 4
(3,278 Views)
Hello,
 
I would be glad to help you with this issue. You can write a simple comparison function to use within the ListRemoveDuplicates function that uses strncmp. I have included an example below:
 
int CVICALLBACK MyCompareFunction(void * item1,void * item2)
{
 
  int MyInt;
  MyInt = strncmp(item1,item2,100);
  return MyInt;
}
 
This should work great. As a side note, you will want to make sure that your character arrays contain enough characters to represent a NUL at the end of each string.
 
I hope this helps!
 
Casey Weltzin
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,256 Views)
Would I then call this fuction as such:  ListRemoveDuplicates (List_Session , MyCompareFunction(item1,item2));  and  how would I initialize item1 and item2?  Would one call to ListRemoveDuplicates go thru the entire list or would I need to increment item1 and item2 and call repeatedly?
 
 
0 Kudos
Message 3 of 4
(3,242 Views)
Hello,
 
Your call to the ListRemoveDuplicates function should resemble the following:
 
ListRemoveDuplicates(MyList,strncmp);
 
The ListRemoveDuplicates function will automatically call your comparison function (in this case strncmp) for each combination of list items, so you only need to call it once. I hope this answers your questions, please let me know if you need any more help. Have a great morning!
 
Regards,
 
Casey Weltzin
Applications Engineer
National Instruments
0 Kudos
Message 4 of 4
(3,224 Views)