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

[ad_1]

                                                

Algorithm:

 

step 1:begin

 

step 2:declare a,b as character array

 

step 3:enter b 

 

step 4:print “unique string”,b

 

step 5:carry out strcpy() operation

 

step 6:print “copied string”,a

 

step 7:cease

 

 Flowchart:

 


 

 

 Code

#embody <stdio.h>

int important()

{

    char a[100],b[100];

    printf(“Enter a String:”);

    will get(b);

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

    strcpy(a,b);

    printf(nCopied String:%s,a);

    return 0;

}

 

Pattern Enter and Output

 

Enter a String:Mumbai                                                                                                                

Unique String:Mumbai                                                                                                               

Copied String:Mumbai 

 

Rationalization of above program 

 

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

 

strcpy()

the strcpy() operate is an ordinary library operate 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 by which the string goes to be copied.

The operate of strcpy() operate 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 have now outlined header file stdio.h  which is used to import printf() and scanf() operate for use to study extra about header file click on right here we have now already coated fundamentals of C.Within the second line of  code we have now outlined important operate with return sort int,return sort int means operate will return integer worth we may give any return sort like char,float,int and so forth(different person outlined

datatype created utilizing construction and union).Within the subsequent line of code we’re declaring two array of character,it should 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() operate 

 

will get()

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

 

 

 

 Within the subsequent line of code,we have now written ‘ “Unique 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 have now realized that each one the assertion that are enclosed inside double quotes will  we printed as it’s,after that we have now put %s in printf() operate,right here %s is format specifier for string variable which we have now 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() operate 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 have now written strcpy(a,b) as a result of we In b variable we have now 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 operate,which inform us that this system is execute efficiently and did what it was meant to do.

 

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

 

You probably have realized one thing new from this put up then share this put up with your loved ones and
mates.

 

Pleased Studying :)?  

[ad_2]

Leave a Reply

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