From b9cd42541689de76a8c7eab020cfe3055c87b4cf Mon Sep 17 00:00:00 2001 From: AnonymusRaccoon Date: Thu, 2 Jan 2020 17:25:50 +0100 Subject: [PATCH] Adding a child count function --- Makefile | 3 ++- include/xml.h | 1 + src/child.c | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/child.c diff --git a/Makefile b/Makefile index 5808b20..58b24dd 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,8 @@ SRC = src/xmlparser.c \ src/rawnode.c \ src/xml_destroy.c \ src/xmlget.c \ - src/floatutils.c + src/floatutils.c \ + src/child.c OBJ = $(SRC:%.c=%.o) diff --git a/include/xml.h b/include/xml.h index d1c906d..bb769dd 100644 --- a/include/xml.h +++ b/include/xml.h @@ -32,4 +32,5 @@ node *xml_getnode(node *parent, const char *name); char *xml_getproperty(node *n, const char *key); int xml_getintprop(node *n, const char *key); float xml_getfloatprop(node *n, const char *key); +int xml_getchildcount(node *n); void xml_destroy(node *n); \ No newline at end of file diff --git a/src/child.c b/src/child.c new file mode 100644 index 0000000..48283fa --- /dev/null +++ b/src/child.c @@ -0,0 +1,22 @@ +/* +** EPITECH PROJECT, 2020 +** Twac +** File description: +** child +*/ + +#include "xml.h" + +int xml_getchildcount(node *n) +{ + int i = 1; + + if (!n || !n->child) + return (0); + n = n->child; + while (n->next) { + n = n->next; + i++; + } + return (i); +} \ No newline at end of file