1 Commits

Author SHA1 Message Date
e0c01fe321 Добавить Task4.cpp 2025-11-04 18:47:39 +02:00
4 changed files with 32 additions and 127 deletions

32
Task4.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin("..\\MyFile\\info.txt");
if (!fin) {
cout << "Error: open input file!!\n";
system("pause");
return 1;
}
char s[100];
char a;
int count = 0;
cout << "Enter the character:";
cin >> a;
while (fin >> s) {
if (tolower(s[0]) == tolower(a)) {
count++;
}
}
cout << "Number of words starting with '" << a << "': " << count << endl;
fin.close();
system("pause");
}

View File

@@ -1,21 +0,0 @@
#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");
}

View File

@@ -1,53 +0,0 @@
#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");
}

View File

@@ -1,53 +0,0 @@
#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");
}