search
HomeComputer TutorialsComputer KnowledgeC programming: use a loop to concatenate two strings and avoid using the strcat function

C language programming: 5. Write a program to connect two strings without using the strcat function

Idea: String concatenation requires determining the end position of the first string, then placing the elements of the second string after the first string, and finally adding the end mark.

Reference code: splicing 123 and 456

#include

void mystrcat(char a[],char b[]){//String connection function

int i=0,j=0;

while(a[i ]!='\0'); //Find the end position of a

i--;

while(b[j]!='\0'){//Assign b element to a

a[i ]=b[j ];

}

a[i]='\0'; //Add end mark

}

int main()

{

char a[100],b[100];

scanf("%s%s",a,b);

mystrcat(a,b);

puts(a);

return 0;

}

/*

operation result:

123 456

123456

*/

How to solve string concatenation in C language?

You can use the string connection function strcat() function, the header file is #include;

Examples are as follows:

Two strings char [100]="abc",b[50]="def";

Convert it into a string and output

#include

#include

int main()

{

char a[100]="abc",b[50]="def";

strcat(a,b);

printf("%s\n",a);

}

C programming: use a loop to concatenate two strings and avoid using the strcat function

Expand information

C language is a general computer programming language that is widely used in low-level development. The design goal of the C language is to provide a programming language that can be easily compiled, handle low-level memory, generate a small amount of machine code, and can run without any runtime environment support.

Although C language provides many low-level processing functions, it still maintains good cross-platform characteristics. C language programs written in a standard specification can be compiled on many computer platforms, even including some embedded processors. (Single-chip microcomputer or MCU) and supercomputers and other operating platforms.

In the 1980s, in order to avoid differences in the C language syntax used by various developers, the American National Bureau of Standards formulated a complete set of American national standard syntax for C language, called ANSI C, as the C language original standard. Currently, on December 8, 2011, the C11 standard released by the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC) is the third official standard of the C language and the latest standard of the C language. This standard better supports Chinese characters. Function names and Chinese character identifiers realize Chinese character programming to a certain extent.

C language is a process-oriented computer programming language, which is different from object-oriented programming languages ​​such as C and Java.

Its compilers mainly include Clang, GCC, WIN-TC, SUBLIME, MSVC, Turbo C, etc.

The above is the detailed content of C programming: use a loop to concatenate two strings and avoid using the strcat function. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Excel办公网. If there is any infringement, please contact admin@php.cn delete
How to Use Roblox Quick Login on PC/Phone? Here Is a Full Guide! - MiniToolHow to Use Roblox Quick Login on PC/Phone? Here Is a Full Guide! - MiniToolApr 28, 2025 am 12:50 AM

If you want to log in to your Roblox account on a new device without inputting the password, Roblox Quick Login can help you do that. This post from php.cn tells you how to use the Roblox quick login feature with full steps.

PS5 vs Xbox Series vs PC: Which One Is Best for Hogwarts Legacy - MiniToolPS5 vs Xbox Series vs PC: Which One Is Best for Hogwarts Legacy - MiniToolApr 28, 2025 am 12:49 AM

Hogwarts Legacy is out now on PS5, Xbox Series X/S, and PC. Which is best for Hogwarts Legacy? If you’re confused, don’t worry. In this post, php.cn provides a tutorial about Hogwarts Legacy PC vs PS5 vs Xbox Series X/S, and you can have a look.

Download Realtek USB GbE Family Controller Drivers Windows 10/11 - MiniToolDownload Realtek USB GbE Family Controller Drivers Windows 10/11 - MiniToolApr 28, 2025 am 12:48 AM

In this post, php.cn Software will show you some information about Realtek USB GbE Family Controller, including its definition, usage, and how to download the Realtek USB GbE Family Controller driver on your Windows 10/11 computer.

Crucial T700 SSD Overview: It Has Record-Break Performance - MiniToolCrucial T700 SSD Overview: It Has Record-Break Performance - MiniToolApr 28, 2025 am 12:47 AM

Crucial T700 PCIe Gen5 NVMe SSD has been released for a period. You can follow this post to learn the related information about this SSD that has record-break performance. In this post, we also introduce some php.cn software to help you manage the SS

How to Download, Install, and Update RTX 4090 Drivers Win 10/11? - MiniToolHow to Download, Install, and Update RTX 4090 Drivers Win 10/11? - MiniToolApr 28, 2025 am 12:46 AM

If you have a GeForce RTX 4090 Ti in hand, it is important to download and install the corresponding driver in time to make it work properly. If you are confused about how to do that, follow this guide on php.cn Website to get a detailed tutorial.

Notion Dark Mode: How to Turn on and off on Desktop & Mobile - MiniToolNotion Dark Mode: How to Turn on and off on Desktop & Mobile - MiniToolApr 28, 2025 am 12:45 AM

Most people think that it is more harmful to look at a screen in the dark. The sharp light easily makes your eyes damaged. Therefore, many people will pursue a dark mode to lower the damage. But is it really useful? Is the dark mode available on Noti

How to Fix Valheim Stuck on Loading Screen? - MiniToolHow to Fix Valheim Stuck on Loading Screen? - MiniToolApr 28, 2025 am 12:44 AM

If you are complaining of Valheim stuck on loading screen and don’t know what to do. This guide on php.cn Website will help you to find suitable solutions. Try the solutions mentioned below one by one until your issue is gone.

Power Tactics to Disable and Clear Run History on WindowsPower Tactics to Disable and Clear Run History on WindowsApr 28, 2025 am 12:43 AM

If you frequently use the Run window to directly open tools or documents, you will find the matching list gradually becomes longer and longer. Some people are searching for methods to clear Run history to make it look clean. This php.cn post might gi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor