Init commit basic stdin reading
This commit is contained in:
commit
5709799fdd
3 changed files with 57 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/dvorak_typing_practice
|
||||||
|
/objects/
|
26
Makefile
Normal file
26
Makefile
Normal file
|
@ -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
|
29
src/main.cc
Normal file
29
src/main.cc
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
std::string get_next_word() {
|
||||||
|
std::string word;
|
||||||
|
while (std::cin.good()) {
|
||||||
|
int in = std::cin.get();
|
||||||
|
if (in != std::char_traits<char>::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;
|
||||||
|
}
|
Loading…
Reference in a new issue