diff --git a/d01/ex04/Makefile b/d01/ex04/Makefile new file mode 100644 index 0000000..81dd985 --- /dev/null +++ b/d01/ex04/Makefile @@ -0,0 +1,61 @@ +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . name = value . name is case sensitive # +# VARIABLES . or name = value \ . use VPATH only for .c # +# . value . or .cpp # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +NAME = sed + +CC = clang++ +CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 -g3 + +VPATH = $(D_SRCS) + +LIBS = + +INCLUDES = -I$(D_HEADERS) + +D_SRCS = . +SRCS = main.cpp + +D_HEADERS = . +HEADERS = + +D_OBJS = builds +OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o) + +RM_D_OBJS = rm -rf $(D_OBJS) +ifeq "$(D_OBJS)" "." +RM_D_OBJS = +endif + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . target: prerequisites . $@ : target # +# RULES . recipe . $< : 1st prerequisite # +# . recipe . $^ : all prerequisites # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +all: $(NAME) + +$(D_OBJS)/%.o: %.cpp | $(D_OBJS) + $(CC) $(CFLAGS) -c $< -o $@ + +$(D_OBJS): + mkdir $@ + +$(OBJS): $(HEADERS:%=$(D_HEADERS)/%) + +$(NAME): $(OBJS) + $(CC) $(OBJS) -o $@ $(LIBS) + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + $(RM_D_OBJS) + +re: fclean all + +.PHONY : all clean fclean re bonus run valgrind diff --git a/d01/ex04/main.cpp b/d01/ex04/main.cpp new file mode 100644 index 0000000..e60f061 --- /dev/null +++ b/d01/ex04/main.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +int main() { + + std::ifstream file("test.txt"); + + // read words separated by whitespaces or newlines +// std::string str; +// while (file >> str) +// std::cout << str << std::endl; + + // skip whitespaces or newlines +// char c; +// while (file >> c) +// std::cout << c << std::endl; + + // seems good + char c; + while (file.get(c)) + std::cout << c; + +} diff --git a/d01/ex04/sed b/d01/ex04/sed new file mode 100755 index 0000000..a254043 Binary files /dev/null and b/d01/ex04/sed differ diff --git a/d01/ex04/test.txt b/d01/ex04/test.txt new file mode 100644 index 0000000..3547a3f --- /dev/null +++ b/d01/ex04/test.txt @@ -0,0 +1,27 @@ +No 1 more tears, my heart is dry +I don't laugh and I don't cry +I don't think about you all the time +But when I do - I wonder why + +You have to go out of my door +And leave just like you did before +I know I said that I was sure +But rich men can't imagine poor. + +One day baby, we'll be old +Oh baby, we'll be old +And think of all the stories that we could have told + +Little me and little you +Kept doing all the things they do +They never really think it through +Like I can never think you're true + +Here I go again - the blame +The guilt, the pain, the hurt, the shame +The founding fathers of our plane +That's stuck in heavy clouds of rain. + +One day baby, we'll be old +Oh baby, we'll be old +And think of all the stories that we could have told