diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-07-03 21:20:32 -0400 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-07-03 21:20:32 -0400 |
| commit | 7b3cb7088d59fca697b04832737e6a6d06d00ea6 (patch) | |
| tree | 731b959726dac8f2cc51ff38e96c0909d233d46f /src/main.c | |
| download | cli-7b3cb7088d59fca697b04832737e6a6d06d00ea6.zip | |
Initial Commit
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..6623f18 --- /dev/null +++ b/src/main.c @@ -0,0 +1,36 @@ +#include <stdbool.h> +#include <stdio.h> +#include <string.h> +#include "linebuffer.h" +#include "word.h" + +#define MAX_WORD_LENGTH 20 + +int main(void) { + char word[MAX_WORD_LENGTH + 2]; + size_t word_length; + int err; + LineBuffer *lb = linebuffer_create(40); + + while (true) { + err = read_word(stdin, word, MAX_WORD_LENGTH + 1); + if (err == EOF) { + printf("Error reading word\n"); + return 1; + } + word_length = strlen(word); + if (word_length == 0) { + linebuffer_write(lb, stdout); + return 0; + } + if (word_length > MAX_WORD_LENGTH) { + word[MAX_WORD_LENGTH] = '*'; + } + if (word_length + 1 > linebuffer_space_remaining(lb)) { + linebuffer_write_justified(lb, stdout); + linebuffer_clear(lb); + } + linebuffer_append_word(lb, word); + } +} + |