String splitting example
#include <stdio.h>
#include <stdlib.h>
int main(
int argc,
char **argv) {
gru_split(
"fedora,freebsd,gentoo,debian,ubuntu,red hat",
',', &status);
uint32_t expected_size = 6;
fprintf(stderr,
"%s\n", status.
message);
goto err_failure;
}
if (list_size != expected_size) {
fprintf(stderr, "Expected %d but got %d\n", expected_size, list_size);
goto err_failure;
}
const char *expected[] = {
"fedora", "freebsd", "gentoo", "debian", "ubuntu", "red hat"};
for (uint32_t i = 0; i < list_size; i++) {
char *data = (
char *) node->
data;
printf("%d = %s\n", i, data);
if (strcmp(data, expected[i]) != 0) {
fprintf(stderr, "Expected %s but got %s\n", expected[i], data);
goto err_failure;
}
}
return EXIT_SUCCESS;
err_failure:
return EXIT_FAILURE;
}