From 63df5c6ee46a12ef19efb2dc9ed67fee73e50860 Mon Sep 17 00:00:00 2001 From: Tait Hoyem <44244401+TTWNO@users.noreply.github.com> Date: Tue, 11 Jun 2019 09:42:14 +0000 Subject: [PATCH] Allow for unlimited buffer, it will only read 56k of data at a time, however --- morse.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/morse.c b/morse.c index 892878f..ac6f829 100644 --- a/morse.c +++ b/morse.c @@ -13,6 +13,8 @@ static const char LOWERCASE_LETTERS[NUM_OF_LETTERS] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; static const char UPPERCASE_LETTERS[NUM_OF_LETTERS] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; +// 6 spaces are needed to store the null terminator :) +// C is fun? static const char MORSE[NUM_OF_LETTERS][6] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "-----"}; void print_single_morse(char charToMorse, bool isSlow, bool addLetter){ @@ -64,6 +66,10 @@ void print_morse(char* strToMorse, bool isSlow, bool addLetter){ } } +void print_unmorsed(char* morseToNormalize){ + +} + int main(int argc, char *argv[]){ bool addLetterBeforeMorse = false; @@ -79,8 +85,13 @@ int main(int argc, char *argv[]){ addLetterBeforeMorse = true; } } - scanf("%[^\n]s", inputString); - print_morse(inputString, isSlow, addLetterBeforeMorse); + + while (fgets(inputString, MAX_INPUT_SIZE, stdin)!=0){ + print_morse(inputString, isSlow, addLetterBeforeMorse); + printf("\n"); + fflush(stdout); + fflush(stdin); + } printf("\n"); return 0;