Man page of tw_get_categories(3)
Index
NAME
tw_get_categories - get a list of categories
SYNOPSIS
C/C++ #include <tw.h> tw_errno_t tw_get_categories(tw_t *tw, char ***cats);
DESCRIPTION
tw_get_categories() generates a list of all categories known to the Textweiser database.
PARAMETERS
- tw (tw_t *)
-
Pointer to an initialized Textweiser object.
- cats (char ***)
-
Pointer to pointer to pointer to char.
Declare cats as a pointer to pointer to
charand initialize it withNULL. Pass a pointer to cats to tw_get_categories().If tw_get_categories() succeeds, cats will contain a
NULLterminated array of categories.If an error occurs or no categories could be found within the database, the value pointed to by cats is set to
NULL.APPLICATION CODE EXAMPLE:
C/C++ char **cats = NULL; tw_get_categories(&tw, &cats);
For a complete example, have a look at EXAMPLE below.
RETURN VALUE
tw_get_categories() returns an error indicator (tw_errno_t).
A return value of TW_OK indicates success, any other value discriminates
the occurred error.
The function tw_strerror(3) can be used to obtain a natural language error message.
NOTES
- o
-
The generated list of categories is sorted alphabetically.
- o
-
If an error occurs or no categories could be found within the database, the value pointed to by cats is set to
NULL. - o
-
On Windows, tw_free_categories(3) has to be used to free the memory allocated for the category listing. On any other OS the use of tw_free_categories(3) is recommended.
EXAMPLE
C/C++ #include <stdio.h> #include <stdlib.h> #include <tw.h> int main(int argc, char *argv[]) { tw_errno_t rv = TW_OK; char **cats = NULL; tw_t tw = TW_INITIALIZER; /* Initialize a Textweiser object using the SQLite * database backend. */ rv = tw_init(&tw, NULL, NULL, NULL, "example.sqlt", 0); if (rv != TW_OK) { fprintf(stderr, "Failed to initialize: %s\n", tw_strerror(rv)); return EXIT_FAILURE; } rv = tw_get_categories(&tw, &cats); tw_free(&tw); if (rv == TW_OK && cats) { size_t i = 0; for (i = 0; cats[i]; i++) { printf("Category %02lu: \"%s\"\n", (unsigned long) i + 1, cats[i]); } tw_free_categories(cats); return EXIT_SUCCESS; } return EXIT_FAILURE; }
Example output:
Category 01: "Economy & Markets" Category 02: "Holidays" Category 03: "Sports" Category 04: "TV"
SEE ALSO
tw_add_category(3), tw_delete_category(3), tw_rename_category(3), tw_strerror(3)
Textweiser User Manual
http://www.lingua-systems.com/text-classifier/textweiser-library/
COPYRIGHT
Copyright (c) 2010-2011 Lingua-Systems Software GmbH


