Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <conio.h>
- #include <stdio.h>
- using namespace std;
- void genCharArr(char* arr) {
- //cout << sizeof(arr) / sizeof(arr[0]) << endl;
- int sz = _msize(arr) / sizeof(arr[0]);
- for (int k = 0; k < sz; ++k) {
- arr[k] = rand() % 256;
- }
- }
- void showCharArr(char* arr) {
- int sz = _msize(arr) / sizeof(arr[0]);
- for (int k = 0; k < sz; ++k) {
- cout << arr[k];
- }
- cout << endl;
- }
- void task1() {
- int sz = 10;
- char *pArr = new char[sz];
- //char Arr[13]{};
- genCharArr(pArr);
- showCharArr(pArr);
- //cout << sizeof(Arr) / sizeof(Arr[0]) << endl;
- delete[] pArr;
- }
- void test_str2() {
- char str1[100]{ "Hello" };
- char str2[]{ " world" };
- strcat_s(str1, str2);
- strcat_s(str1, str2);
- cout << str1 << endl;
- strncat_s(str1, str2, 20);
- cout << str1 << endl;
- char* str3 = new char[]{ "hffhwadswsda" };
- cout << strchr(str3, 'w') << endl;
- cout << "Compare: " << _stricmp("ABC", "aBC") << endl;
- cout << "Compare: " << strcmp("DFG", "ABC") << endl;
- cout << "Compare: " << strcmp("ABC", "ABC") << endl;
- cout << "Length: " << strlen("ABCDE fg") << endl;
- char strBig[]{ "ABCdefg" };
- _strlwr_s(strBig);
- cout << "small: " << strBig << endl;
- _strupr_s(strBig);
- cout << "big: " << strBig << endl;
- _strrev(strBig);
- cout << "reverce: " << strBig << endl;
- _strnset_s(strBig, '$', 12);
- cout << strBig << endl;
- cout << strspn("ABCDEF", "EF") << endl; // ?????
- char strBig2[]{"Let me speak about the bus." };
- char* first = strstr(strBig2, "buss");
- if (first)
- cout << "It find" << endl;
- else
- cout << "Dose not find." << endl;
- //strtok_s(strBig2, " ", ppStr); // не знаем
- double x = atof("12.5");
- cout << x * 1.1 << endl;
- int k = atoi("163");
- cout << k + 23 << endl;
- long long big = atoll("12345678998545");
- cout << big << endl;
- cout << "long long: " << sizeof(long long) << endl;
- cout << "long: " << sizeof(long) << endl;
- cout << "int: " << sizeof(int) << endl;
- if (!_itoa_s(1457.6565, strBig2, 10)) {
- cout << strBig2 << endl;
- }
- }
- void test_str() {
- /*
- putchar('R');
- char ch = getchar();
- cout << "You enter char: " << ch << endl;
- ch = _getch(); // #include <conio.h>
- cout << "You enter char: " << ch << endl;
- */
- char str[1024];
- gets_s(str); //#include <stdio.h>
- //cout << str;
- puts("Hello world");
- }
- void task2() {
- auto name = "Hello world";
- cout << name << endl;
- const char starr[] = "Hello world";
- cout << starr << endl;
- const char* starr2 = new char[] {"Hello world"};
- cout << starr2 << endl;
- char starr4[]{ "Hel\0 \t \n lo" };
- char starr5[]{ 'H', 'e', 'l', 'l', 'o' };
- cout << sizeof(starr4) / sizeof(starr4[0]) << endl;
- cout << sizeof(starr5) / sizeof(starr5[0]) << endl;
- cout << starr5 << endl;
- cout << '\0' << endl;
- char ch1[]{"a"};
- char ch2[]{'a'};
- }
- void my_replace(
- char* str,
- char oldChar,
- char newChar) {
- int k = 0;
- while (str[k]!= '\0') {
- if (str[k] == oldChar)
- str[k] = newChar;
- ++k;
- }
- }
- void my_replace(
- char* &str,
- char oldChar,
- char* newChar) {
- int size_str = _msize(str) / sizeof(str[0]);
- int size_newChar = _msize(newChar) / sizeof(newChar[0]);
- int count = 0;
- int k = 0;
- while (str[k] != '\0') {
- if (str[k] == oldChar)
- count++;
- ++k;
- }
- if (count > 0) {
- char* buff = new char[size_str - count + (size_newChar-1) * count];
- int m = 0;
- k = 0;
- while (str[k] != '\0') {
- if (str[k] == oldChar) {
- for (int n = 0; n < size_newChar - 1; ++n) {
- buff[m] = newChar[n];
- ++m;
- }
- }
- else {
- buff[m] = str[k];
- ++m;
- }
- ++k;
- }
- buff[m] = str[k];
- delete[] str;
- str = buff;
- }
- }
- void test_my_replace() {
- char* str = new char[] {"abcdeabcde"};
- char* sub_str = new char[] {"xyz"};
- my_replace(str, 'a', sub_str);
- cout << str << endl;
- delete[] str;
- delete[] sub_str;
- }
- void test_concat() {
- char name[]{ "Ivan" };
- char fathername[]{"Nikolaevic"};
- char sername[]{"Kovalev"};
- char full_name[1024]{}; // "Ivan Nikolaevic Kovalev"
- strcat_s(full_name, name);
- strcat_s(full_name, " ");
- strcat_s(full_name, fathername);
- strcat_s(full_name, " ");
- strcat_s(full_name, sername);
- cout << full_name << endl;
- }
- void main() {
- //task1();
- //task2();
- //test_str();
- //task3();
- //test_my_replace();
- test_concat();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement