int main(int argc, char *argv[]) { if (argc < 4) { fatal("Usage: %s hostname port message\n", argv[0]); } String_pointer message = String_fromCString(argv[3]); TCPConnection_pointer connection = TCP_connect(argv[2], argv[1]); TCP_sendMessage(connection, message); String_pointer received = TCP_receiveMessage(connection); puts(String_toCstring(received)); String_destroy(received); String_destroy(message); TCP_closeAndDestroyConnection(connection); return 0; }
int main() { String * myKey, *myKey2, *myValue, *tmpString; List * keys; ListIterator * iterator; HashTable * table = HashTable_create(500); myKey = String_create("Mia"); myKey2 = String_create("Russell"); myValue = String_create("shrug"); HashTable_setValue(table, myKey, String_copy(myValue)); HashTable_setValue(table, myKey2, String_copy(myValue)); String_destroy(myValue); keys = HashTable_getKeys(table); iterator = ListIterator_create(keys); tmpString = ListIterator_seekToFirst(iterator); while(tmpString != NULL) { myValue = HashTable_removeValue(table, tmpString); printf("Removed -> %s\n", String_c(myValue)); String_destroy(myValue); tmpString = ListIterator_seekToFirst(iterator); } ListIterator_destroy(iterator); String_destroy(myKey); String_destroy(myKey2); HashTable_destroy(table); return 0; }
/// static methods and private typedefs; private or virtual methods implementations static void String_vdestroy(void *vthis) { String_destroy(STRING(vthis)); }
void StringPile_burn(StringPile *pile) { for (int i = 0; i < pile->filled; i++) { String_destroy(pile->elements[i]); } pile->filled = 0; }