add syllable.c

This commit is contained in:
Vlasta Vesely 2018-04-25 15:16:12 +02:00
parent 44cc47701e
commit b52f8610ad
3 changed files with 47 additions and 1 deletions

View file

@ -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
View 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
View 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 */