C language does not use strcat function to realize the function code of connecting two strings

Time:2022-5-1

String concatenation function:

String connection is to connect one string to the end of another string and combine it into a new string. In the string processing function, strcat # function has the function of string connection. The following is the function of connecting two strings in C language without using strcat function.

Source code:

#include<stdio.h>
 
void constring(char s[],char t[],char q[]);     // Function declaration
 
int main(void)
{
  char s[100];
  char q[100];
  char t[200];
  Printf ("the input string is s: \ n")// Prompt for string
  gets(s);                             // Input string
  Printf ("input string Q: \ n");
  gets(q);
  constring(s, q, t);                    // Call function
  Printf ("string after connection is:% s \ n", t);
}
 
void constring(chars[],char t[], char q[])     
{
  int i, j;
  for (i = 0; s[i] != '
#include<stdio.h>
void constring(char s[],char t[],char q[]);     // Function declaration
int main(void)
{
char s[100];
char q[100];
char t[200];
Printf ("the input string is s: \ n")// Prompt for string
gets(s);                             // Input string
Printf ("input string Q: \ n");
gets(q);
constring(s, q, t);                    // Call function
Printf ("string after connection is:% s \ n", t);
}
void constring(chars[],char t[], char q[])     
{
int i, j;
for (i = 0; s[i] != '\0'; i++)
{
q[i] = s[i];
}
for (j = 0; t[j] != '\0'; j++)
{
q[i + j] = t[j];
}
q[i + j] = '\0';
}
'; i++) { q[i] = s[i]; } for (j = 0; t[j] != '
#include<stdio.h>
void constring(char s[],char t[],char q[]);     // Function declaration
int main(void)
{
char s[100];
char q[100];
char t[200];
Printf ("the input string is s: \ n")// Prompt for string
gets(s);                             // Input string
Printf ("input string Q: \ n");
gets(q);
constring(s, q, t);                    // Call function
Printf ("string after connection is:% s \ n", t);
}
void constring(chars[],char t[], char q[])     
{
int i, j;
for (i = 0; s[i] != '\0'; i++)
{
q[i] = s[i];
}
for (j = 0; t[j] != '\0'; j++)
{
q[i + j] = t[j];
}
q[i + j] = '\0';
}
'; j++) { q[i + j] = t[j]; } q[i + j] = '
#include<stdio.h>
void constring(char s[],char t[],char q[]);     // Function declaration
int main(void)
{
char s[100];
char q[100];
char t[200];
Printf ("the input string is s: \ n")// Prompt for string
gets(s);                             // Input string
Printf ("input string Q: \ n");
gets(q);
constring(s, q, t);                    // Call function
Printf ("string after connection is:% s \ n", t);
}
void constring(chars[],char t[], char q[])     
{
int i, j;
for (i = 0; s[i] != '\0'; i++)
{
q[i] = s[i];
}
for (j = 0; t[j] != '\0'; j++)
{
q[i + j] = t[j];
}
q[i + j] = '\0';
}
'; }

Operation results:

The above C language does not use strcat function to realize the function code of connecting two strings, which is all the content shared by Xiaobian. I hope it can give you a reference and support developeppaer.

Recommended Today

JVM + GC parsing (premise knowledge concatenation)

Premise preparation JVM GC garbage collection JVM virtual machine monitoring, tuning and troubleshooting Tomcat and microservice optimization 1. Premise review 1.1. JVM memory structure 1.1.1、 JVM Architecture Overview The gray part in the figure isThread private, there is almost no garbage collectionOrange partThread sharing, the main place where garbage recycling occurs What is the class […]