c program to concatenate two strings 

list of concatenation programs:C program to concatenate two strings using strcat() function, C program to concatenate two strings without strcat() function i.e. C program to concatenate two strings using arrays or C program to concatenate two strings using pointers.

c program to concatenate two strings using strcat function
c program to concatenate two strings using strcat function

The word concatenate means is to combine or append two strings. For example there are two strings twenty and two, the concatenation of these two strings is twentytwo. There are three methods to concatenate strings. We can write a c program to concatenate two strings using strcat function,  using pointers and using arrays.
strcat Function: strcat string function is used to concatenate two strings. strcat is available under string.h file. The function takes two strings as inputs or parameters and output a string which is concatenation of two strings and save in first string.
syntax: strcat( string str1 string str2)

write a c program to concatenate two strings using strcat function

write a c program to concatenate two strings using strcat function/ write a C program for concatenation of two strings in array

#include<stdio.h>
#include<conio.h>
// string.h contains built in string functions
#include<string.h>
void main()
{
char str1[30], str2[30];
int i:
printf(“..To concatenate two strings usind strcat…”)
printf(“Enter first string “);
gets(str1);
printf(“Enter next string to concatenate “);
gets(str2);
strcat(str1, str2); //concatenates str1 & str2 and saves in str1
printf(“concatenation of two strings using strcat is %s\n”,str1);
getch();
}

OUTPUT:

..To concatenate tw0 strings using strcat…

Enter first string
one

Enter next string to concatenate
two

concatenation of two strings using strcat is
onetwo

write a c program to concatenate ten strings using strcat function

write a c program to concatenate two strings using strcat function

#include<stdio.h>
#include<conio.h>
// string.h contains built in string functions
#include<string.h>
void main()
{
char str[30], str2[30];
int i:
printf(“..To concatenate ten strings usind strcat…”)
printf(“Enter first string “);
gets(str1);
for( i=1;i<10;i++) //you can set n intead of 10 for multiple strings
{
printf(“Enter next string to concatenate “);
gets(str2); // To concatenate a space add strCat( str1, ” “); next to this
strcat(str1, str2); //concatenates str1 & str2 and saves in str1
}
printf(“concatenation of ten strings using strcat is %s\n”,str1);
getch();
}

OUTPUT:

..To concatenate ten strings using strcat…

Enter first string
one

Enter next string to concatenate
two

Enter next string to concatenate
three

Enter next string to concatenate
four

Enter next string to concatenate
five

Enter next string to concatenate
six

Enter next string to concatenate
seven

Enter next string to concatenate
eight

Enter next string to concatenate
nine

Enter next string to concatenate
ten

concatenation of ten strings using strcat is onetwothreefourfivesixseveneightnineten

 

c program to concatenate two strings using pointers without strCat

c program to concatenate two strings using pointers without strCatconcatenation using pointers program logic:
Take two strings str1 & str2 . Move the  pointer until end of string str1 after which increment position of str1 and save first character in str2 and so on until end of str2. str1 contains concatenation of two strings

write a C Program to concatenate two strings using pointers

write a c program to concatenate two strings using pointers

#include<stdio.h>
#include<conio.h>
void main()
{
char *str1, *str2;
printf(” … c program to concatenate two strings without strcat() using arrays…”)
printf(“Enter first string “);
gets(str1);
printf(“Enter second string “);
gets(str2);
while (*str1!=’\0′)
*str1++ ;
while (*str2!=’\0′)
*str1++=*str2++
printf(“concatenation of two strings using pointers is %s\n”,str1);
getch();
}

OUTPUT:

… c program to concatenate two strings without strcat() using arrays…

Enter first string
programming
Enter second string
simplysolved
concatenation of two strings without strcat using pointers is programmingsimplysolved

write a C Program to concatenate two strings using functions

write a c program to concatenate two strings using functions and pointers

#include<stdio.h>
#include<conio.h>
void main()
{
char *str1, *str2;
printf(” … To concatenate two strings without strcat() using functions…”)
printf(“Enter first string “);
gets(str1);
printf(“Enter second string “);
gets(str2);
str_concatinate(*str1, *str2)
getch();
}

void str_concatinate(char *string1, char *string2)
{
while (*string1!=’\0′)
*string1++ ;
while (*string2!=’\0′)
*string1++=*string2++;
printf(“concatenation of two strings without strcat using functions is %s\n”,string1);
}

OUTPUT:

… To concatenate two strings without strcat using functions;…

Enter first string
programming
Enter second string
simplysolved
concatenation of two strings without strcat using functions is programmingsimplysolved

c program to concatenate two strings using arrays without strCat function, n stringsc program to concatenate two strings using arrays without strCat function, n strings

 

concatenation using arrays program logic:
Take two strings str1 & str2 . Move the array INDEX / pointer until end of string str1 after which increment position of str1 and save first character in str2 and so on until end of str2.str1 contains concatenation of two strings

write a C Program to concatenate two strings using arrays in function

write a C Program to concatenate two strings using arrays write logic in function

#include<stdio.h>
#include<conio.h>
void main()
{
char str1[100], str2[100];
printf(” …To concatenate two strings without strCat using for loop”)
printf(“Enter first string “);
gets(str1);
printf(“Enter second string “);
gets(str2);
str_Concatenate( str1,str2);
getch();
}

void str_Concatenate( char string1[100] ,char  string2[100])
{
for (i=0; string1[i]!=null; i++){
}
for(j=0; string2[j]!=null; j++)
{
string1[i]=string2[j];
i++
}
printf(“concatenation of two strings without strCat using arrays is %s\n”,string1);

}

OUTPUT:

… To concatenate two strings without strCat using for loop

Enter first string
An
Enter second string
Apple
concatenation of two strings without strCat using arrays is AnApple

write a C Program to concatenate two strings using arrays


write a C Program to concatenate two strings using arrays / write a C Program for concatenation of two strings without strcat

#include<stdio.h>
#include<conio.h>
void main()
{
char str1[100], str2[100];
printf(” …To concatenate two strings without strCat using while loop”)
printf(“Enter first string “);
gets(str1);
printf(“Enter second string “);
gets(str2);
int i=0;
while (str1[i]!=null)
i++;
int j=0;
while (str2[j]!=null)
{
str1[i] =str2[j];
i++;
j++;
}
printf(“concatenation of two strings without strCat using arrays is %s\n”,str1);
getch();
}

OUTPUT:

… To concatenate two strings without strCat using while loop

Enter first string

hai

Enter second string

hello

concatenation of two strings without strCat using arrays is haihello

Other programs:

Static variable scope
Register variable scope
External variable scope
Automatic variable scope
amicable number
Prime number
Perfect number
Palindrome number
Strong number
Find Factorial 
Biggest Number
Average of n numbers
convert decimal number to octal
decimal number to hexadecimal
decimal number to binary
simple interest
compound interest
Add sparce matrices
Add matrices
 file copying
Palindrome string
Reverse string
String length
Replace characters in string
substring or not using arrays
First occurrence of character in string
Last occurrence of character in string
Convert to uppercase
Convert to lowercase
Concatenate strings 
Compare strings
Generate Employee payslips
Count students scoring marks>50%
convert weight into grams

 

Leave a Reply

Your email address will not be published. Required fields are marked *