12#include "helpers/split.h"
30 char* text =
STRDUP(textToDisplay);
33 split(text,
"\n", &lines);
37 printf(
" %2d) %s\n", lineNumber, lines.
strings[index]);
44 printf(
" Error! Out of memory duplicating text to display with lines!\n");
53"/*#################### Block Comment #################################*/\n"
54"//#################### Line Comment ####################################\n"
55"// A comment. /* A nested comment */\n"
57"void State_Exercise() // An exercise in state machines\n"
59" char character = '\\\"';\n"
61" printf(\"\\\"State\\\" /*Exercise*/\\n\");\n"
63" bool success = State_RemoveComments(textToFilter, &filteredText);\n"
65" printf(\"\\t\\tDone. //(No, really)//\\n\");\n"
85 printf(
"\nState_Exercise\n");
87 printf(
" Text to filter:\n");
90 printf(
" Filtering text...\n");
95 printf(
" Filtered text:\n");
void State_Exercise(void)
Example of using the State Pattern.
static const char * textToFilter
static void _State_DisplayText(const char *textToDisplay)
Helper function to display text from the State exercise. Text is displayed with line numbers.
Declaration of the State_Exercise() function as used in the State Pattern.
void DynamicString_Clear(DynamicString *string)
Clear a DynamicString object, releasing any allocated memory. Resets to an empty string.
Declaration of the DynamicString structure and supporting functions to work with dynamic strings.
void split(char *s, const char *splitChars, SplitList *components)
Split the given path into multiple strings based on the given delimiter. The pointers to each string ...
Declaration of the STRDUP macro that hides the differences between how strdup() is declared in differ...
#define STRDUP
Define STRDUP to be the operating system-specific version of strdup().
Represents a string that can be grown dynamically.
char * string
The string that can grow.
Represents a collection of sub-strings split from a single string using the split() function.
size_t strings_count
Number of sub-strings.
const char ** strings
Pointers to each sub-string.