aboutsummaryrefslogtreecommitdiff
path: root/week06/Exercise07.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'week06/Exercise07.cpp')
-rw-r--r--week06/Exercise07.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/week06/Exercise07.cpp b/week06/Exercise07.cpp
new file mode 100644
index 0000000..2e07a0c
--- /dev/null
+++ b/week06/Exercise07.cpp
@@ -0,0 +1,37 @@
+#include <fstream>
+#include <iostream>
+
+int main() {
+ int m, n;
+ std::cin >> m >> n;
+
+ char fileName[1024];
+ std::cin.ignore();
+ std::cin.getline(fileName, 1024);
+
+ std::ifstream file(fileName);
+ if (!file.is_open()) {
+ std::cout << "Couldn't open file!" << std::endl;
+ return 1;
+ }
+
+ unsigned lineIndex = 1;
+ while (!file.eof()) {
+ if (file.peek() == '\n') {
+ lineIndex = 1;
+ file.get();
+ std::cout << std::endl;
+ continue;
+ }
+
+ if (m <= lineIndex && lineIndex <= n) {
+ std::cout << (char)file.peek();
+ }
+
+ lineIndex++;
+ file.get();
+ }
+ std::cout << std::endl;
+
+ file.close();
+}