Advertisement
avr39ripe

PV024strPractice

Dec 17th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void printString(char* str, int maxSize)
  4. {
  5.     while (*str != '\0')
  6.     {
  7.         std::cout << *str++;
  8.     }
  9.     std::cout << '\n';
  10. }
  11.  
  12. int strlenM(char* str)
  13. {
  14.     int len{0};
  15.     while (*str)
  16.     {
  17.         ++len;
  18.         ++str;
  19.     }
  20.     return len;
  21. }
  22.  
  23. // "ABC\0" // [ABCx]
  24. void strdupM(char* src, char* dest)
  25. {
  26.     while (*src)
  27.     {
  28.         *dest++ = *src++;
  29.     }
  30.     *dest = '\0';
  31. }
  32.  
  33. // void strdnupM(char* src, int maxSize, char* dest)
  34.  
  35. int main()
  36. {
  37.     int val{};
  38.  
  39.     char symb{ 'A' };
  40.     char str2[4]{ "ABC" };
  41.     char* chPtr{ nullptr};
  42.  
  43.     chPtr = &symb;
  44.     chPtr = str2;
  45.     chPtr = new char[10];
  46.  
  47.  
  48.     std::cout << "Hello, world!\n";
  49.     //char str[50]{'A','l','e','x','a',' ', 'f','r','o','m',' ', 'G', 'o','o','g','l','e'};
  50.     char str[18]{ "Alexa from Google" };
  51.     //char str1[50]; //char const* str1
  52.     char* str1{ new char[5]{} };
  53.  
  54.     strndupM(str, 5, str1); // "Alex\0"
  55.  
  56.     str[11] = 'Z';
  57.  
  58.     printString(str1, 50);
  59.     std::cout << "Length of the string is " << strlenM(str1) << '\n';
  60.  
  61.     printString(str, 50);
  62.     std::cout << "Length of the string is " << strlenM(str) << '\n';
  63.     delete[] str1;
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement