How to write a C Program To Find Length Of String And Concatenate Two Strings in C Programming
Solution For C Program :/* C program which read two strings and concatenate the largest string to the smallest string (among the two strings).*/
#include<stdio.h>
#include<string.h>
#include<conio.h>
int leng(char str[20]);
void concat(char str4[20], char str5[20]);
void main()
{
char str1[20],str2[20],str3[20];
int i,j,len,first,second;
clrscr();
printf("Enter the first string:\n");
gets(str1);
printf("Enter the second string:\n");
gets(str2);
first=leng(str1);
second=leng(str2);
printf("\nLength of 1st string= %d",first);
printf("\nLength of 2nd string= %d",second);
if(first<=second)
{
concat(str1,str2);
}
else
{
concat(str2,str1);
}
getch();
}
int leng(char str[20])
{
int i=0;
while(str[i]!='\0')
{
i++;
}
return(i);
}
void concat(char str4[20], char str5[20])
{
int i=0,j;
char str6[20];
while(str4[i]!='\0')
{
str6[i]=str4[i];
i++;
}
j=0;
while(str5[j]!='\0')
{
str6[i]=str5[j];
i++;j++;
}
str6[i]='\0';
printf("\n\nConcanated string= %s",str6);
}
You may also learn these C Program/Code :
C Program To Swap Two Numbers Without Using Third Variable
Learn More :
Concatenate
Length
- C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters
- C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not
- C Program to calculate Area, Perimeter of Rectangle; Area, Circumference of Circle.
- C Program to find string length without library function
- C Program that prompts the user to input a string, (whitespaces allowed)
- Menu driven program in C to Calculate Length, Copy into Another Compare Concatenate of Two String
Find
- Find out the perfect number using c program
- Find g.c.d of two number using c program.
- Write a c program to find out NCR factor of given number
- How to Write a C program to find maximum between two numbers ?
- Write a C program to find maximum between three numbers ?
- C or C++ program to read marks of 4 subjects and find how many students are pass and fail with division
- C Program turnLEDOn to Drives Forward Until It Finds The Line
- Write overloaded function templates for finding the roots of the linear (a * x + b = 0) and square (a * x2 + b * x + c = 0) uravneniy.Zamechanie: in function to send coefficients of the equations.
- C Program to Find Random Number
- C Program To Find LCM and HCF Of Two Number Using Function - 2
- C Program to find LCM and HCF Of Two Number Using Recursion - 3
- C Program To Find LCM and HCF Of Two Number -1
- C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters
- C Program To Find Product Of Two No Using MACRO
- C Program To Find Reverse Of Any Digit Number
- C Program To Find Sum and Difference Of Two Matrices
- C Program To Find The Frequency Of A Number
- C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not
- C Program To Find The Maximum And Minimum Value In An Array
- C Program To Find Transpose Of A Matrix
- C Program To Find Union & Intersection Of Two Array
- C Program Finding the sum of Squares using Recursion
- C Program to Find NCR Of A Given Number Program
- C Program To Find Maximum Of Given Numbers
String
- Write a c program to check given string is palindrome number or not.
- C Program to Convert Text String to Binary
- C Program String - Alphabet Count Example
- C Program String Example
- C Program String Count Example
- C Program String Example
- C Program to Print a String Without Use Semicolon.
- C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters
- C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not
- C Program To Print String In Formatted Output Form
- C Program To Reverse The String Using Pointer
- C Program Concatenating Two Strings Into A Third System
- C Program Date from string DDDD-DD-DD
- BUILDS A STRING FROM THE LSB BITS OF EACH PIXEL
- C Program Finds Sub-String Search in String
- C Program to concatenate two strings without using string functions
- C Program to Count Vowels, Consonants and Spaces in a string
- C Program to convert a string to upper case
- C Program Performs a search and replace for a specified target and replacement string
- C Program Anagrams
- C Program to find string length without library function
- C Program to Check Given String is Palindrome or Not
- C Program to Converts a Number to a String.
- Design a C function that shortens a string to 8 characters