add syllable.c
This commit is contained in:
parent
44cc47701e
commit
b52f8610ad
3 changed files with 47 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
|||
.PHONY: all clean
|
||||
|
||||
all:
|
||||
$(CC) main.c -o main
|
||||
$(CC) main.c syllable.c -o main
|
||||
./main
|
||||
|
||||
clean:
|
||||
|
|
32
syllable.c
Normal file
32
syllable.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "syllable.h"
|
||||
|
||||
|
||||
struct syllable *syllable_alloc(const char *data)
|
||||
{
|
||||
struct syllable *ptr = malloc(sizeof(*ptr));
|
||||
|
||||
if (ptr == NULL)
|
||||
return NULL;
|
||||
|
||||
ptr->data = strdup(data);
|
||||
ptr->next = NULL;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void syllable_drop(struct syllable *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
struct syllable *syllable_append(struct syllable *tail, const char *data)
|
||||
{
|
||||
struct syllable *ptr;
|
||||
|
||||
ptr = syllable_alloc(data);
|
||||
tail->next = ptr;
|
||||
|
||||
return ptr;
|
||||
}
|
14
syllable.h
Normal file
14
syllable.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef __SYLLABE_H
|
||||
#define __SYLLABE_H
|
||||
|
||||
struct syllable {
|
||||
char *data;
|
||||
struct syllable *next;
|
||||
};
|
||||
|
||||
struct syllable *syllable_alloc();
|
||||
void syllable_drop(struct syllable *syllable);
|
||||
|
||||
struct syllable *syllable_append(struct syllable *tail, const char *data);
|
||||
|
||||
#endif /* __SYLLABE_H */
|
Loading…
Add table
Reference in a new issue