commit 5709799fdd3cee73070432744c4b549b85d9f6d1 Author: Stephen Seo Date: Thu Dec 14 17:00:08 2023 +0900 Init commit basic stdin reading diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd0ac6e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/dvorak_typing_practice +/objects/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b9233e2 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +ifdef RELEASE +CXX_FLAGS = -Wall -Wextra -Wpedantic -O3 -DNDEBUG +else +CXX_FLAGS = -Wall -Wextra -Wpedantic -Og -g +endif + +OBJDIR = objects + +SOURCES = src/main.cc + +OBJECTS = $(addprefix ${OBJDIR}/,$(subst .cc,.o,${SOURCES})) + +all: dvorak_typing_practice + +dvorak_typing_practice: ${OBJECTS} + ${CXX} ${CXX_FLAGS} -o dvorak_typing_practice $^ -lraylib + +${OBJDIR}/%.o: %.cc + @mkdir -p $$(dirname $@) + ${CXX} ${CXX_FLAGS} -c -o $@ $< + +.PHONY: clean + +clean: + rm -rf ${OBJDIR} + rm -f dvorak_typing_practice diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 0000000..18e4a2b --- /dev/null +++ b/src/main.cc @@ -0,0 +1,29 @@ +#include +#include + +std::string get_next_word() { + std::string word; + while (std::cin.good()) { + int in = std::cin.get(); + if (in != std::char_traits::eof() && in != ' ' && in != '\n' && in != '\r') { + word.push_back((char)in); + } else if (in == ' '|| in == '\n' || in == '\r' || in == '\t') { + break; + } + } + + return word; +} + +int main() { + std::string word; + + do { + word = get_next_word(); + if (!word.empty()) { + std::cout << word << '\n'; + } + } while (!std::cin.eof()); + + return 0; +}