Petro_zzz

new_lesson10

Sep 14th, 2022
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. void genCharArr(char* arr) {
  10.     //cout << sizeof(arr) / sizeof(arr[0]) << endl;
  11.     int sz = _msize(arr) / sizeof(arr[0]);
  12.     for (int k = 0; k < sz; ++k) {
  13.         arr[k] = rand() % 256;
  14.     }
  15. }
  16.  
  17. void showCharArr(char* arr) {
  18.     int sz = _msize(arr) / sizeof(arr[0]);
  19.     for (int k = 0; k < sz; ++k) {
  20.         cout << arr[k];
  21.     }
  22.     cout << endl;
  23. }
  24.  
  25. void task1() {
  26.     int sz = 10;
  27.     char *pArr = new char[sz];
  28.     //char Arr[13]{};
  29.     genCharArr(pArr);
  30.     showCharArr(pArr);
  31.     //cout << sizeof(Arr) / sizeof(Arr[0]) << endl;
  32.     delete[] pArr;
  33. }
  34.  
  35. void test_str() {
  36.     char str1[100]{ "Hello" };
  37.     char str2[]{ " world" };
  38.     strcat_s(str1, str2);
  39.     strcat_s(str1, str2);
  40.     cout << str1 << endl;
  41.  
  42.     strncat_s(str1, str2, 20);
  43.     cout << str1 << endl;
  44.  
  45.     char* str3 = new char[]{ "hffhwadswsda" };
  46.     cout << strchr(str3, 'w') << endl;
  47.  
  48.     cout << "Compare: " << _stricmp("ABC", "aBC") << endl;
  49.     cout << "Compare: " << strcmp("DFG", "ABC") << endl;
  50.     cout << "Compare: " << strcmp("ABC", "ABC") << endl;
  51.  
  52.     cout << "Length: " << strlen("ABCDE fg") << endl;
  53.    
  54.     char strBig[]{ "ABCdefg" };
  55.     _strlwr_s(strBig);
  56.     cout << "small: " << strBig << endl;
  57.  
  58.     _strupr_s(strBig);
  59.     cout << "big: " << strBig << endl;
  60.  
  61.     _strrev(strBig);
  62.     cout << "reverce: " << strBig << endl;
  63.  
  64.     _strnset_s(strBig, '$', 12);
  65.     cout << strBig << endl;
  66.  
  67.     cout << strspn("ABCDEF", "EF") << endl; // ?????
  68.    
  69.     char strBig2[]{"Let me speak about the bus." };
  70.     char* first = strstr(strBig2, "buss");
  71.     if (first)
  72.         cout << "It find" << endl;
  73.     else
  74.         cout << "Dose not find." << endl;
  75.     //strtok_s(strBig2, " ", ppStr); // не знаем
  76.     double x = atof("12.5");
  77.     cout << x * 1.1 << endl;
  78.     int k = atoi("163");
  79.     cout << k + 23 << endl;
  80.     long long big = atoll("12345678998545");
  81.     cout << big << endl;
  82.     cout << "long long: " << sizeof(long long) << endl;
  83.     cout << "long: " << sizeof(long) << endl;
  84.     cout << "int: "  << sizeof(int) << endl;
  85.     if (!_itoa_s(1457.6565, strBig2, 10)) {
  86.         cout << strBig2 << endl;
  87.     }
  88. }
  89.  
  90. void task3() {
  91.     /*
  92.     putchar('R');
  93.  
  94.     char ch = getchar();
  95.     cout << "You enter char: " << ch << endl;
  96.    
  97.     ch = _getch(); // #include <conio.h>
  98.     cout << "You enter char: " << ch << endl;
  99.     */
  100.     char str[1024];
  101.     gets_s(str); //#include <stdio.h>
  102.     //cout << str;
  103.     puts("Hello world");
  104. }
  105.  
  106. void task2() {
  107.     auto name = "Hello world";
  108.     cout << name << endl;
  109.  
  110.     const char starr[] = "Hello world";
  111.     cout << starr << endl;
  112.  
  113.     const char* starr2 = new char[] {"Hello world"};
  114.     cout << starr2 << endl;
  115.  
  116.     char starr4[]{ "Hel\0 \t \n lo" };
  117.     char starr5[]{ 'H', 'e', 'l', 'l', 'o' };
  118.  
  119.     cout << sizeof(starr4) / sizeof(starr4[0]) << endl;
  120.     cout << sizeof(starr5) / sizeof(starr5[0]) << endl;
  121.     cout << starr5 << endl;
  122.  
  123.     cout << '\0' << endl;
  124.  
  125.     char ch1[]{ "a" };
  126.     char ch2[]{ 'a' };
  127. }
  128.  
  129. void main() {
  130.     //task1();
  131.     //task2();
  132.     //test_str();
  133.     task3();
  134. }
Advertisement
Add Comment
Please, Sign In to add comment