I have a bunch of strings that look like:
'Hello1-FOO', 'Aello2-FOO', 'Bye1-BAR', 'Bye3-BAR', 'Hello22-FOO', 'Bye4-BAR', 'Welcome-BAR' ...
All of them are stored on a struct.
struct str {
char *strings;
}
...
struct str **t_str;
size_t j;
t_str = malloc(sizeof *t_str * 20);
for (j = 0; j < 20; j++)
t_str[j] = malloc(sizeof *t_str[j]);
...
t_str[0]->strings = "Hello1-FOO";
t_str[1]->strings = "Aello2-FOO";
....
What I would like to do is to display (sort) them by category, so they look similar to this:
FOO:
Hello1-FOO
Aello2-FOO
Hello22-FOO
BAR:
Bye4-BAR
Welcome-BAR
Bye1-BAR
Bye3-BAR
Basically group them by the token after the '-'
What would be a good way of doing this? Should I store them on a second struct after processing the string? Any idea will be appreciated. Thanks
strinstance for each string? That's what your code looks like, but the description made it sound like you wanted to store all the strings in a singlestrinstance