3 Commits

Author SHA1 Message Date
553478ff06 Добавить task4.cpp 2025-10-07 20:33:07 +03:00
6696b68f67 Добавить task2.cpp 2025-10-07 20:04:29 +03:00
5f709cc80a Добавить task1.cpp 2025-10-07 19:23:55 +03:00
3 changed files with 127 additions and 0 deletions

21
task1.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include <iostream>
#define SIZE 80
using namespace std;
int main()
{
char str[SIZE];
cout << "Input string: ";
cin.getline(str, SIZE);
int i = 0;
while (str[i] != '\0') {
if (str[i] == ' ') {
str[i] = '\t';
}
++i;
}
cout << "Modified string: " << str << endl;
system("pause");
}

53
task2.cpp Normal file
View File

@@ -0,0 +1,53 @@
#pragma warning(disable : 4996)
#define SIZE 80
#include <iostream>
using namespace std;
int mystrlen(const char* str) {
int len = 0;
for (; str[len] != '\0'; ++len) {}
return len;
}
char* mystrcat(char* str1, const char* str2) {
int i = mystrlen(str1);
int j;
for (j = 0; str2[j] != '\0'; ++j) {
str1[i + j] = str2[j];
}
str1[i + j] = '\0';
return str1;
}
char* mystrchr(char* str, char s) {
for (int i = 0; str[i] != '\0'; ++i) {
if (str[i] == s) {
return &str[i];
}
}
return 0;
}
int main() {
char str1[SIZE];
char str2[SIZE];
cout << "Input first string: ";
cin.getline(str1, SIZE);
cout << "Input second string: ";
cin.getline(str2, SIZE);
cout << "mystrlen(str1): " << mystrlen(str1) << endl;
cout << "mystrcat(str1, str2): " << mystrcat(str1, str2) << endl;
char ch;
cout << "Input char to search in str1: ";
cin >> ch;
char* f = mystrchr(str1, ch);
if (f) {
cout << "mystrchr(str1, '" << ch << "): " << f << endl;
}
else {
cout << "mystrchr(str1, '" << ch << "): 0" << endl;
}
system("pause");
}

53
task4.cpp Normal file
View File

@@ -0,0 +1,53 @@
#pragma warning(disable : 4996)
#define SIZE 80
#include <iostream>
using namespace std;
int mystrlen(const char* str) {
int len = 0;
for (; str[len] != '\0'; ++len) {}
return len;
}
char* mystrcat(char* str1, const char* str2) {
int i = mystrlen(str1);
int j = mystrlen(str2);
for (int k = 0; k < j; ++k) {
str1[i + k] = str2[k];
}
str1[i + j] = '\0';
return str1;
}
char* mystrchr(char* str, char s) {
for (int i = 0; str[i] != '\0'; ++i) {
if (str[i] == s) {
return &str[i];
}
}
return 0;
}
int main() {
char str1[SIZE];
char str2[SIZE];
cout << "Input first string: ";
cin.getline(str1, SIZE);
cout << "Input second string: ";
cin.getline(str2, SIZE);
cout << "mystrlen(str1): " << mystrlen(str1) << endl;
cout << "mystrcat(str1, str2): " << mystrcat(str1, str2) << endl;
char ch;
cout << "Input char to search in str1: ";
cin >> ch;
char* f = mystrchr(str1, ch);
if (f) {
cout << "mystrchr(str1, '" << ch << "'): " << f << endl;
}
else {
cout << "mystrchr(str1, '" << ch << "'): 0" << endl;
}
system("pause");
}