Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- char * NotEmptyArr(char* arr) {
- string str = arr;
- while (str.length() == 0) {
- cout << "The input cannot be empty"<<endl;
- cin.getline(arr, 100);
- str = arr;
- }
- return arr;
- }
- void PrintResultString(string str1, string str2) {
- int maxSize = 0;
- int minSize = 0;
- if (str1.length() > str2.length()) {
- maxSize = str1.length();
- minSize = str2.length();
- }
- else {
- maxSize = str2.length();
- minSize = str1.length();
- }
- int counter = 0;
- string result[100];
- for (int i = 0; i < maxSize; i++)
- {
- if (maxSize == str1.length()) {
- result[i] = str2[counter];
- if (counter == str2.length() - 1) {
- counter = -1;
- }
- counter++;
- }
- else {
- result[i] = str1[counter];
- if (counter == str1.length() - 1) {
- counter = -1;
- }
- counter++;
- }
- }
- for (int i = 0; i < maxSize; i++)
- {
- cout << result[i];
- }
- }
- int main()
- {
- char arr1[100];
- char arr2[100];
- cout << "arr1= ";
- cin.getline(arr1, 100);
- //check if arr1 is empty
- string str1 = NotEmptyArr(arr1);
- cout << "arr2= ";
- cin.getline(arr2, 100);
- //check if arr2 is empty
- string str2 = NotEmptyArr(arr2);
- //check whether the two strings are of different size
- if (str1.length() == str2.length()) {
- cout << "The inputs should be of different size. "<<endl;
- return main();
- }
- PrintResultString(str1, str2);
- //!!!!!! trqbva funkciqta da e string, a ne void i da vrushta result
- //kak da proverq dali nqkoj masiv e prazen
- //zashto ne raboti
- //cout << result;
- // kak da izpechatam rezultata bez cikul
- //zashto ne moga na masiv da prisvoq stoinostta na string
- // \t ...ne raboti kato primera ako stoinostta na stringa e vkarana ot konzolata- tova normalno li e?
- // pri proverkata dali e empty ne mi izliza tekst: arr1/2= ....
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement