Sunday, October 13, 2024
HomeC ProgrammingC Program to repeat one string into one other utilizing strcpy() perform

C Program to repeat one string into one other utilizing strcpy() perform


                                                

Algorithm:

 

step 1:begin

 

step 2:declare a,b as character array

 

step 3:enter b 

 

step 4:print “authentic string”,b

 

step 5:carry out strcpy() operation

 

step 6:print “copied string”,a

 

step 7:cease

 

 Flowchart:

 


 

 

 Code

#embody <stdio.h>

int primary()

{

    char a[100],b[100];

    printf(“Enter a String:”);

    will get(b);

    printf(“Authentic String:%s,b);

    strcpy(a,b);

    printf(nCopied String:%s,a);

    return 0;

}

 

Pattern Enter and Output

 

Enter a String:Mumbai                                                                                                                

Authentic String:Mumbai                                                                                                               

Copied String:Mumbai 

 

Clarification of above program 

 

In above Program we’re copying one string and storing it into one other utilizing strcpy() perform

 

strcpy()

the strcpy() perform is a normal library perform in C/C++.

Parameters related to strcpy()

strcpy(vacation spot,supply)

supply:supply factors to the variable the place the string that’s to be copied is saved.

vacation spot:It factors to the variable during which the string goes to be copied.

The perform of strcpy() perform is solely copying the content material of supply  variable into vacation spot variable.

 

 

Let’s perceive line by line 

 

Within the first line of code we’ve got outlined header file stdio.h  which is used to import printf() and scanf() perform for use to study extra about header file click on right here we’ve got already coated fundamentals of C.Within the second line of  code we’ve got outlined primary perform with return sort int,return sort int means perform will return integer worth we may give any return sort like char,float,int and many others(different person outlined

datatype created utilizing construction and union).Within the subsequent line of code we’re declaring two array of character,it’ll act as a string not directly as a result of string is nothing however an array of character.

 

 

Within the subsequent line of code,we’re merely printing the message “Enter a string”  after which we’re taking enter in string format utilizing will get() perform 

 

will get()

this perform is used to take enter in string format  and retailer the end result within the  given variable which is handed in will get() perform.The will get() and places() are declared within the header file stdio.h. Each the
features are concerned within the enter/output operations of the strings.This perform allows the person to enter some character adopted by the enter key.

 

 

 

 Within the subsequent line of code,we’ve got written ‘ “Authentic String:”%s,b’ On this Line the primary a part of line is inside double code which will likely be printed as it’s As we’ve got realized that every one the assertion that are enclosed inside double quotes will  we printed as it’s,after that we’ve got put %s in printf() perform,right here %s is format specifier for string variable which we’ve got talked about instantly after it i.e b variable.So lastly have been are on essentially the most import line of code i.e the place the precise operation of program is getting carried out.strcpy() perform takes two argument the primary is the place the copied string ought to be saved and the second argument from which variable string ought to be copied.

In our program we’ve got written strcpy(a,b) as a result of we In b variable we’ve got the saved the string that’s to copied and a varible is empty string in order that the when carry out strcpy(a,b) the string saved in b variable will get copied right into a variable.Within the second final line of code we’re merely printing the copied string utilizing printf().Within the final line of code we’re merely returning 0 to the primary perform,which inform us that this system is execute efficiently and did what it was meant to do.

 

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

 

In case you have realized one thing new from this put up then share this put up with your loved ones and
associates.

 

Completely happy Studying :)😎  

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments