[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:
#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
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 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]