Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int my_strlen(char *str) {
- int n = 0;
- while (str[n] != '\0')
- n++;
- return n;
- }
- void my_strcpy(char *source, char *target) {
- int i = 0;
- while ((source[i] = target[i]) != '\0')
- i++;
- source[i] = target[i];
- }
- int my_strstr(char *haystack, char *needle) {
- int k, count = 0, len, c = 0;
- len = my_strlen(needle);
- for (int i = 0; haystack[i] != '\0'; i++) {
- c++;
- k = i;
- for (int j = 0; needle[j] != '\0'; j++) {
- if (haystack[k] != needle[j])
- break;
- count++;
- k++;
- }
- if (count == len)
- return i + 1;
- count = 0;
- }
- return -1;
- }
- int main() {
- char a[] = "";
- int method;
- cout << "Enter the desired function (strlen - 1, strcpy - 2, strstr - 3)" << endl;
- cin >> method;
- if (method == 1) {
- int kol = my_strlen(a);
- cout << kol;
- }
- if (method == 2) {
- char b[] = "";
- my_strcpy(a, b);
- for (int i = 0; i < my_strlen(a); i++){
- cout << a[i];
- }
- }
- if (method == 3) {
- char b[] = "";
- cout << my_strstr(a, b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment