Friday, March 29, 2024
HomeC ProgrammingC Program to concatenate two String Utilizing strcat() operate

C Program to concatenate two String Utilizing strcat() operate


 

 

 

Algorithm:

 

step 1:begin

 

step 2:declare a,b as character array

 

step 3:enter a,b 

 

step 4:carry out strcat() operation

 

step 5:print the concatenated string

 

step 6:cease

 

 

 

Flowchart:

 

Code:

 


#embrace <stdio.h>

#embrace<string.h>

int major() {

    char a[100],b[100];

    printf(“Enter Your Identify:”);

    will get(a);

    printf(“Enter Your Surname:”);

    will get(b);

    strcat(a,b);

    printf(“Your full title is %s,a);

    

    

    return 0;

}

Pattern Enter and Output:

Enter Your Identify:Pankaj                                                                                                                 

Enter Your Surname:Jaiswal

Your full title is PankajJaiswal            

Clarification of above program 

 

In above Program we’re concatenating one string with one other string utilizing strcat() operate

char *strcat(char *vacation spot,char *supply)

The full type of strcat()  operate is string concatenation.It is without doubt one of the inbuilt string operate which is supplied by string.h header file in C,it helps to concatenate two string those that do not what’s concatenation,it’s nothing however combining one string with one other,I identified most of you continue to have the confuse for  the identical,So Let’s take an instance to know extra clearly.

first_string=”Good”

second_string=”Morning”

strcat(first_string,second_string)

After passing above two string values to strcat() operate the end result could be GoodMorning and it is going to be saved within the vacation spot argument i.e first_string(as per syntax of strcat()).We are able to merely say that the results of concatenation of first_string and second_string can be saved in first_string.

Now Let’s Perceive the code line by line which we’ve got written above

For understanding extra clearly about C Program to concatenate two String Utilizing strcat() operate we’ve got took the instance during which Person will put his/her first and final title and our program will give him his/her FullName.

Within the first line of code we’re importing stdio.h header file which assist us to make use of printf() and scanf().stdio.h is a acronym of ordinary enter output header file.Within the subsequent line we’re importing string.h header file which offer completely different string associated capabilities like strcmp(),stringcpy(),strcat(),

places(),will get() and plenty of extra.

After that we’ve got outlined major operate during which we’ve got written all of the assertion that are going to be executed,as we identified the execution of c program begins from major() operate solely.

Within the subsequent line,we’ve got declared two character array(string) specifically a,b which we can be utilizing to saved two string respectively.After that we’ve got printed one assertion “Enter Your First Identify” which assist the consumer to get to identified that the applying is ready to your enter.For taking consumer enter as string or character array we’ve got used will get() operate.As soon as the consumer put his/her first title this system will ask for lastname(right here additionally we’re doing the identical factor which we have been doing for firstname),the second consumer put his/her final title the concatenated results of two string can be printed,to attain this we’re concatenating two string utilizing strcat() functiom which we’ve got already seen above the way it works.

Within the subsequent line of code we’re printing the results of concatenation utilizing printf() operate.Right here we’ve got written printf(“Your Full title is  %s”,a).Right here “Your Full title is” can be printed as it’s and the worth of  a personality array during which the concatenated sting is saved can be printed.

Within the final line of code we’re merely returning return 0 which imply that the execution of program is generally executed.It’s essential to return the worth if we’ve got wrote the int return of any operate,In our case it’s major() which is int return sort.

If you happen to any have doubt,suggestion relating to this put up or web site then be at liberty to share with us.

 

When you have discovered one thing new from this put up then share this put up with your loved ones and
buddies.

 

Completely happy Studying :)😎   

 

Earlier
Subsequent

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments