String connection (implemented in C)

Source: Internet
Author: User

Cause
Today, I found that a code that does not call any c library function to achieve String concatenation is too complicated for many people to write, and the linked list is used up, as long as you know that the final cutoff character of the string is '\ 0 '.

Description:
Without using any string library function, we can accept two strings without redundancy and then connect them without redundancy.
Input:
Each line contains two strings and the length cannot exceed 100.
Output:
Multiple groups of test data may exist. For each group of data,
Without using any string library function, we can accept two strings without redundancy and then connect them without redundancy.
Output the connected string.
Sample input:
Abc def
Sample output:
Abcdef

Go directly to my AC code
[Cpp]
# Include <stdio. h>
# Include <stdlib. h>
 
Void contact (char * str, const char * str1, const char * str2 );
Www.2cto.com
Int main ()
{
Char str [2, 201], str1 [101], str2 [101];
 
While (scanf ("% s", str1, str2 )! = EOF)
{
Contact (str, str1, str2 );
Printf ("% s \ n", str );
}
Return 0;
}
 
/**
* Description: String concatenation Function
*/
Void contact (char * str, const char * str1, const char * str2)
{
Int I, j;

For (I = 0; str1 [I]! = '\ 0'; I ++)
{
Str [I] = str1 [I];
}
For (j = 0; str2 [j]! = '\ 0'; j ++)
{
Str [I + j] = str2 [j];
}
Str [I + j] = '\ 0 ';
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.