aboutsummaryrefslogtreecommitdiff
path: root/Converter/src/main.c
diff options
context:
space:
mode:
authordx <aryadevchavali1@gmail.com>2020-05-06 03:14:03 +0100
committerdx <aryadevchavali1@gmail.com>2020-05-06 03:15:27 +0100
commite779637fc436abbfc7175e613950e52497053976 (patch)
treedc3bacea5ae3f5ddc2335a2ffdedc8944140c146 /Converter/src/main.c
parent74dd237810d47e961f30ff8e9c3a10a4bb9ef7ac (diff)
downloadmdhtml-e779637fc436abbfc7175e613950e52497053976.tar.gz
mdhtml-e779637fc436abbfc7175e613950e52497053976.tar.bz2
mdhtml-e779637fc436abbfc7175e613950e52497053976.zip
~express header algorithm in terms of new constants
untag_size, tag_size, etc. These represent the proper sizes and are easier to mutate.
Diffstat (limited to 'Converter/src/main.c')
-rw-r--r--Converter/src/main.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Converter/src/main.c b/Converter/src/main.c
index e41304b..6dae344 100644
--- a/Converter/src/main.c
+++ b/Converter/src/main.c
@@ -27,13 +27,14 @@ string compile_line(string line, size_t size_of_line)
sprintf(untag, "</h%d>", depth);
// allocate buffer with extra 9 characters for the tags
- compiled_line = malloc(sizeof(*compiled_line) * (size_of_line + 9));
+ compiled_line = malloc(sizeof(*compiled_line) *
+ (size_of_line + tag_size + untag_size));
// write h1 to start of compiled_line
- strncpy(compiled_line, "<h1>", 4);
+ strncpy(compiled_line, tag, tag_size);
// write the rest of the line to the compiled_line
- strncpy(compiled_line + 4, line + 1, size_of_line - 1);
+ strncpy(compiled_line + tag_size, line + depth, size_of_line);
// write the end tags
- strncpy(compiled_line + size_of_line + 3, "</h1>", 5);
+ strncpy(compiled_line + size_of_content + tag_size, untag, untag_size);
}
else