#include
#include
using namespace std;
int main() {
const size_t N = 30;
char s1[N+1], s2[N+1], s3[N+1];
char result[10];
cin.getline(s1, N)
.getline(s2, N)
.getline(s3, N);
strncpy(result, s1, 3);
strncpy(result + strlen(result), s2, 3);
strncpy(result + strlen(result), s3, 3);
cout << result << endl;
return 0;
}
#include
#define BUF_SIZE 10
//-------------------------------------------------------------------
// Выводит в буфер buf три байта из src, начиная с текущей позиции pos
void to_buf( char* buf, size_t buf_size, size_t& pos, const char* src );
//-------------------------------------------------------------------
//-------------------------------------------------------------------
const char* words[] =
{
"volcano",
"demon",
"orthogon"
};
//-------------------------------------------------------------------
//-------------------------------------------------------------------
int main()
{
char buf[BUF_SIZE];
size_t pos = 0;
for( auto& w:words )
{
to_buf( buf, BUF_SIZE, pos, w );
}
std::cout << "BUF: " << buf << std::endl;
return 0;
}
//-------------------------------------------------------------------
// Выводит в буфер buf три байта из src, начиная с текущей позиции pos
void to_buf( char* buf, size_t buf_size, size_t& pos, const char* src )
{
size_t idx = pos;
size_t count = 0;
while( idx < (buf_size - 1) && src[count] && count < 3 )
{
buf[idx] = src[count];
idx++;
count++;
}
buf[idx] = '\0';
pos = idx;
}
//-------------------------------------------------------------------
#include
#include
using namespace std;
int main() {
char word1[31], word2[31], word3[31];
cout << "Enter the first word (3-30 characters): ";
cin.getline(word1, 31);
cout << "Enter the second word (3-30 characters): ";
cin.getline(word2, 31);
cout << "Enter the third word (3-30 characters): ";
cin.getline(word3, 31);
char newWord[10] = {}; //Empty and initializing the array with 0
strncat(newWord, word1, 3);
strncat(newWord, word2, 3);
strncat(newWord, word3, 3);
cout << "The new word is: " << newWord << endl;
return 0;
}
1.Даны три слова (каждое содержит от 3 до 30 символов). Требуется создать новое слово, включающее в себя по 3 первых символа данных слов. ВАЖНО Для хранения использовать Си-строки. Исходные строки должны остаться неизменными.
Пример:
Ввод; Вывод;
volcano voldemort
demon
orthogon