[Top] [Prev] [Next] [Bottom]
[Contents]
SutReplaceNList
Replaces the item at a specified position of an SutList and returns the old item at that position.
#include "SutList.h"
void* SutReplaceNList(pSutList p, int n, void* item);
Arguments
- p
- A pSutList.
- n
- Specifies the position in the pSutList to replace the item.
- item
- The new item that will replace the old item.
Return Values
Replaces and returns the item at a specified position of the SutList. Returns NULL if passed a NULL p
value. Returns NULL, if n is less than 0, or greater than the number of items in the list - 1.
SutReplaceNList replaces and returns the old item at a specified position of a SutList. Returns NULL if passed a NULL p
value. Returns NULL, if n
is less than 0 or greater than the number of items in the list -1. The position parameter is 0 based. The returned item is of type void
*. You must typecast as appropriate to use the item. The SutList structure and related functions manage a dynamically sized array of void pointers which can be used as a generic container for C/C++ programmers. Due to the implementation of the SutList, this is the most efficient way to replace items from a list, i.e., it is faster than the combination of SutRemoveNList and SutAddNList.
#include "SutList.h"
#include <stdio.h>
pSutList list;
int i, size;
char *str;
char* str1 = "Hello";
char* str2 = "World";
char* str3 = "X World";
list = SutNewList();
SutAddList(list, str1);
SutAddList(list, str2);
SutReplaceNList(list, 1, str3);
size = SutSizList(list);
for (i=0; i<size; i++)
{
str = (char*) SutRemoveNList(list, 0);
fprintf(stderr, "%s\n", str);
}
SutDestroyList(list);
See Also
[Top] [Prev] [Next] [Bottom]
[Contents]
info@bluestone.com
Copyright © 1997, Bluestone. All rights
reserved.