-
Notifications
You must be signed in to change notification settings - Fork 0
push homework lesson 6 #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nedav347
wants to merge
1
commit into
main
Choose a base branch
from
lesson_6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /* | ||
| * Домашнее задание к уроку | ||
| * курса "Основы языка С++" | ||
| * автор Недокунев А.В. | ||
| * среда разработки Notepad++ /компилятор MinGW/ | ||
| * codepage UTF-8 | ||
| */ | ||
| #include <iostream> | ||
| #include <fstream> | ||
|
|
||
| void err_open_file(const char *arg){ | ||
| std::cout << "Ошибка открытия файла " << arg << std::endl; | ||
| } | ||
|
|
||
| int concat2file(const char *file1, const char *file2, const char *file3){ | ||
| std::ifstream fin; | ||
| std::ofstream fos; | ||
| fin.open(file1); | ||
| if (!fin.is_open()){ | ||
| err_open_file("1"); | ||
| return 1; | ||
| } | ||
| fin.seekg(0, std::ios_base::end); | ||
| int filesize = fin.tellg(); | ||
| // int countchar = fin.tellg() / sizeof(char); | ||
| // char* char_arr = (char*) calloc(filesize / sizeof(char), sizeof(char)); | ||
| char* char_arr1 = (char*) calloc(filesize, 1); | ||
| fin.seekg(0, std::ios_base::beg); | ||
| fin.get(char_arr1, filesize); | ||
| // std::cout << char_arr1 << std::endl; | ||
| fin.close(); | ||
| fin.open(file2); | ||
| if (!fin.is_open()){ | ||
| err_open_file("2"); | ||
| return 1; | ||
| } | ||
| fin.seekg(0, std::ios_base::end); | ||
| filesize = fin.tellg(); | ||
| char* char_arr2 = (char*) calloc(filesize, 1); | ||
| fin.seekg(0, std::ios_base::beg); | ||
| fin.get(char_arr2, filesize); | ||
| // std::cout << char_arr2 << std::endl; | ||
| fin.close(); | ||
| fos.open(file3); | ||
| if (!fos.is_open()){ | ||
| err_open_file("3"); | ||
| return 1; | ||
| } | ||
| fos << char_arr1 << char_arr2; | ||
| fos.close(); | ||
| return 0; | ||
| } | ||
|
|
||
| int main(int argc, const char** argv){ | ||
| /*Задание 1 | ||
| Написать программу, которая создаст два текстовых файла, | ||
| примерно по 50-100 символов в каждом (особого значения не имеет); | ||
| */ | ||
| std::ofstream fos("lesson6_1.txt"); | ||
| if (!fos.is_open()){ | ||
| err_open_file("4"); | ||
| return 1; | ||
| } | ||
| // fos << "Написать программу, которая создаст два текстовых файла, примерно по 50-100 символов в каждом (особого значения не имеет) << std::endl; | ||
| fos << "Write a program that will create two text files, about 50-100 characters each (does not really matter). " << std::endl; | ||
| fos.close(); | ||
| fos.open("lesson6_2.txt"); | ||
| if (!fos.is_open()){ | ||
| err_open_file("5"); | ||
| return 1; | ||
| } | ||
| // fos << "Написать функцию, «склеивающую» эти файлы, предварительно буферизуя их содержимое в динамически выделенный сегмент памяти нужного размера." << std::endl; | ||
| fos << "Write a function that \"glue\" these files, pre-buffering their contents into a dynamically allocated memory segment of the required size." << std::endl; | ||
| fos.close(); | ||
|
|
||
|
|
||
| /*Задание 2 | ||
| Написать функцию, «склеивающую» эти файлы, | ||
| предварительно буферизуя их содержимое | ||
| в динамически выделенный сегмент памяти нужного размера. | ||
| */ | ||
| if (concat2file("lesson6_1.txt", "lesson6_2.txt", "lesson6_3.txt")){ | ||
| return 1; | ||
| } | ||
|
|
||
|
|
||
| /*Задание 3* | ||
| Написать программу, которая проверяет присутствует ли | ||
| указанное пользователем при запуске программы слово | ||
| в указанном пользователем файле | ||
| (для простоты работаем только с латиницей). | ||
| */ | ||
| std::ifstream fin; | ||
| if (argc < 2){ | ||
| std::cout << "Не введено имя файла!" << std::endl; | ||
| std::cout << "Использование: " << argv[0] << " имя_файла"; | ||
| return 1;//вывести правила использования | ||
| } | ||
| std::string s; | ||
| std::cout << "Введите имя файла: "; | ||
| std::cin >> s; | ||
| fin.open(s); | ||
| if (!fin.is_open()){ | ||
| err_open_file("6"); | ||
| return 1; | ||
| } | ||
| // for(fin >> s; !fin.eof(); fin >> s){ | ||
| // std::cout << s << std::endl; | ||
| // if (s == argv[1]){ | ||
| // std::cout << "\033[31m" << "_Math!!!_" << "\033[0m" << std::endl; | ||
| // return 0; | ||
| // } | ||
| // } | ||
| while (!fin.eof()){ | ||
| fin >> s; | ||
| std::cout << s << std::endl; | ||
| if (s == argv[1]){ | ||
| std::cout << "\033[3;44;93m_Math!!!_\033[0m" << std::endl; | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Write a program that will create two text files, about 50-100 characters each (does not really matter). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Write a function that "glue" these files, pre-buffering their contents into a dynamically allocated memory segment of the required size. |
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
напрашивается функция вместо копипасты, да?