Untitled
unknown
c_cpp
2 years ago
1.0 kB
7
Indexable
#include <iostream>
#include <iomanip>
using namespace std;
int mystrlen(char* stroka) {
char* fsimvol = stroka;
while (*stroka != '\0') {
stroka++;
}
return stroka - fsimvol;
}
char *Mystrstr(char* str1,char* str2) {
for (int i = 0; i < mystrlen(str1); i++) {
int j;
for (j = 0; j < mystrlen(str2); j++) {
if (str1[i + 1] != str2[j]) {
break;
}
}
if (j == mystrlen(str2)) {
return &str1[i];
}
else {
return NULL;
}
}
}
int main()
{
int n1;
cout << "Include n1 = ";
cin >> n1;
char* str1 = new char[n1];
cin >> str1;
cin.getline(str1, n1);
int n2;
cout << "Include n2 = ";
cin >> n2;
char* str2 = new char[n2];
cin >> str2;
cin.getline(str2, n2);
cout << Mystrstr(str1, str2) << endl;
delete[] str1;
delete[] str2;
return 0;
}Editor is loading...
Leave a Comment