Commit 367a2a68 authored by Michael's avatar Michael

michael.davityan:execise_07_36

parent 6d3c86ad
progname=exercise_07_36
CC=g++
CFLAGS=-Wall -Wextra -Werror -g3
all: test1
debug/$(progname): debug/$(progname).o
$(CC) $(CFLAGS) $< -o $@
debug/%.o: debug/%.s
$(CC) -c $(CFLAGS) $< -o $@
debug/%.s: debug/%.ii
$(CC) -S $(CFLAGS) $< -o $@
debug/%.ii: %.cpp | debug
$(CC) -E $(CFLAGS) $< -o $@
debug:
mkdir -p debug
clean:
rm -r debug Tests/*.out
test%: debug/$(progname)
@./debug/$(progname) < Tests/$@.in > Tests/$@.out 2>&1 || echo "$@ is executing..."
@diff Tests/$@.out Tests/$@.expected && echo PASSED || echo FAILED
.PRECIOUS: debug/%.ii debug/%.s
.SECONDARY: debug/%.ii debug/%.s
#include <iostream>
#include <unistd.h>
#include <string>
void
stringReverse(std::string& string, const size_t firstIdx = 0)
{
const int sizeOfString = string.size();
if ('\0' != string[firstIdx]) {
std::cout << string[(sizeOfString - 1) - firstIdx];
return stringReverse(string, firstIdx + 1);
} else {
std::cout << std::endl;
}
}
int
main()
{
if (::isatty(STDIN_FILENO)) {
std::cout << "This program takes string from user\n"
<< "and print it reversed.\n"
<< "insert string: ";
}
std::string string;
std::getline(std::cin, string);
std::cout << "reversed: ";
stringReverse(string);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment