Computer Programming C Laboratory: Practical C Programs

Write a C program to concatenate two strings using dynamic memory allocation

C Program with Algorithm, Flowchart, Output

Simple C Program with Algorithm, Flowchart, Output - Computer Programming - C

Write a program to concatenate two strings using dynamic memory allocation.


AIM

To write a program to concatenate two strings.


ALGORITHM

Step‒1 : Start

Step-2 : Read two string into s1,s2

Step-3 : Allocate memory for s1,s2,s3

Step-4 : Store each character of the string s1 into an array

Step-5 : Store each character of the string s2 into another array

Step-6 : Combine both arrays into one

Step-7 : Print Concatenated string

Step-8 : Stop


FLOWCHART



PROGRAM

#include<stdio.h>

#include<conio.h>

#include<malloc.h>

#define lenght 40

void main()

{

char *s1, *s2,*s3,c;

int i,j,k;

clrscr();

s1=(char*)malloc(lenght * sizeof(char));

s2=(char*)malloc(lenght * sizeof(char));

s3=(char*)malloc(2 *lenght* sizeof(char));

printf("Enter string one :");

scanf("%s",s1);

printf("Enter string two :");

scanf("%s",s2);

i=0;

while((c=*(s1+i))!= '\0')

{

      s3[i]=c;

     i=i+1;

}

k=0;

while((c=*(s2+k)) != '\0')

{

     s3[i+k]=c;

     k=k+1;

}

printf("Concatenated string is: \n");

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

getch();

}


OUTPUT

Enter string one: Muni

Enter string two : Rathnam

Concatenated string is :

Muni Rathnam

 

Computer Programming C Laboratory: Practical C Programs : Tag: C Programming : C Program with Algorithm, Flowchart, Output - Write a C program to concatenate two strings using dynamic memory allocation


Computer Programming C Laboratory: Practical C Programs



Under Subject


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation