syllable.c: add syllable_chain_to_string()
This commit is contained in:
parent
b52f8610ad
commit
e4fbd8bbfb
2 changed files with 32 additions and 0 deletions
29
syllable.c
29
syllable.c
|
@ -30,3 +30,32 @@ struct syllable *syllable_append(struct syllable *tail, const char *data)
|
|||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
unsigned long syllable_chain_length(struct syllable *head)
|
||||
{
|
||||
struct syllable *walk = head;
|
||||
unsigned int length = 0;
|
||||
|
||||
while (walk) {
|
||||
length += strlen(walk->data);
|
||||
walk = walk->next;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
char *syllable_chain_to_string(struct syllable *head)
|
||||
{
|
||||
struct syllable *walk = head;
|
||||
unsigned int length = syllable_chain_length(head);
|
||||
char *buffer = malloc(length + 1);
|
||||
char *ptr = buffer;
|
||||
|
||||
while (walk) {
|
||||
strcpy(ptr, walk->data);
|
||||
ptr += strlen(walk->data);
|
||||
walk = walk->next;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
|
|
@ -11,4 +11,7 @@ void syllable_drop(struct syllable *syllable);
|
|||
|
||||
struct syllable *syllable_append(struct syllable *tail, const char *data);
|
||||
|
||||
unsigned long syllable_chain_length(struct syllable *head);
|
||||
char *syllable_chain_to_string(struct syllable *head);
|
||||
|
||||
#endif /* __SYLLABE_H */
|
||||
|
|
Loading…
Reference in a new issue