Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)
C Program To Copy One String To Another String | 4 Simple Ways
Latest :

C Program To Copy One String To Another String | 4 Simple Ways

C program to copy one string to another string – In this article, we will discuss the available methods to copy one string to another string in C programming.

Suitable examples and sample programs have also been added so that you can understand the whole thing very clearly. The compiler has also been added with which you can execute it yourself.

The methods used in this blog are as follows:

  • Using Standard Method
  • Using Function
  • Using Recursion
  • Using String Library Function

A string is nothing but an array of characters. The value of a string is determined by the terminating character. Its value is considered to be 0.

C Program To Copy One String To Another String

As you can see in the image uploaded above, firstly, you need to enter any random string of your choice.

The string entered here is as follows:

‘cprogram’

Thus, if this string is copied to another empty string, the second string will be like this:

‘cprogram’

Since the second string is empty, the first string is completely copied and the second one becomes a replica of the first.

Thus, the means to do the same in C programming are as follows:

Using Standard Method

  1. Read the entered string using gets() function and store the string into s1.

2) To copy one string into another string

a) Iterate the for loop with the structure for(i=0;s[i]!=’\0′;i++)

copy the elements of the string s1  into the string s2 as s2[i]=s1[i] until the last element of string s1.

b) Every string ends with null so initialize the last element as null in the string s2.

3) Print the original string s1 and copied string s2.

Output:

Using Function

  1. The main() function calls the stringcopy() function by passing s1,s2 as arguments.

2) The function stringcopy() will copy the one string elements into the another string.

a) for loop iterates with the structure for(i=0;s2[i]=s1[i];i++),The element of the string s1[i] will be copied to s2[i] until all iterations of i.

b) After completion of for loop initialize the null value as ending character to the string s2.

3) Then the main() prints the orriginal string s1 and copied string s2.

Output:

Using Recursion

  1. The main() function calls the recursion function stringcopy() by passing s1,s2,0 as arguments.

2) The recursion function

a) Initialize the null value to s2[i] if the element of s1[i]=null

b) Else the element s1[i] will be copied to s2[i].

c) The function calls itself as stringcopy(s1,s2,++i) until the element of the string s1 is null.

3) The main() function will print the elements of string s1 and copied string s2.

Output:

Using String Library Function
  1. The strcpy(string1, string2) is the one of the string library function to copy one string to another string.

2) The strcpy() function is available in string.h header file.

Output:

x

Check Also

C Program To Check If Alphabet, Digit or Special Character | C Programs

C program to check for an alphabet, digit or special character – In this article, ...

bakırköy escortşişli escortsightcareDeneme Bonusu Veren SitelerDeneme Bonusu Veren SitelerDeneme Bonusu Veren SitelerDeneme Bonusu Veren Sitelerdeneme bonusu veren sitelergrandpashabetgrandpashabetGrandpashabetdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelercasinofastbetwoondeneme bonusu veren sitelerdeneme bonusugrandpashabetdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelergrandpashabetgrandpashabetbetgray güncel girişdeneme bonusu veren sitelerDeneme Bonusu Veren Sitelerjokerbet girişjokerbetZlotbetgray güncelcasibomcasibom güncelcasibomhalkalı escortsakarya escortsora watermark removerjojobetJustin tvPinbahisholiganbetmeritking girişgrandpashabet girişimajbet girişgrandpashabet,grandpashabet giriş,grandpashabet güncel giriş1xbet,1xbet giriş,1xbet güncel girişmatbetsuperbetmeritbetbetebetgrandpashabet1xbetimajbetholiganbetdeneme bonusu veren sitelersonbahissonbahis girişpusulabetjojobetbetnanobetsmoveJojobettimebetdinamobetartemisbetartemisbetjojobet girişHoliganbet Girişultrabetbetparkcasibom girişJojobet girişcasibom girişcasibomcasibom girişsolibetsolibet girişsolibet giriş adresisolibetsolibetlunabetmegabahis girişgalabet girişelitbahisgrandpashabetgrandpashabetbetciocasibomjojobetpusulabet girişonwinpusulabetbetciohttps://www.djela-nd.com/casibombahiscasinomeritbetkatlaavrupabetJojobetpadişahbetvaycasinocasibom güncelcasibomcasibom giriştürk ifşabetasusgrandpashabetgrandpashabetpusulabetmeritbet girişmeritkinggrandpashabetvdcasinobetebet girişimajbetcoinbarbetturkey girişjojobet,jojobet giriş,jojobet güncel girişgrandpashabet girişgrandpashabet1xbet giriş1xbetimajbetkatlameritbetmeritbetmeritbetimajbet girişpusulabetjojobetpusulabetmarsbahismavibetmarsbahismarsbahisbetzulagobahis girişbetzula girişgobahishiltonbet girişhiltonbetmarsbahismeritkingcasibomcasibom girişjojobetasyabahisgrandpashabetpusulabetcasibomcasibom girişjojobet girişCasibom güncel girişcasibomcasibom girişpadişahbet girişmarsbahisjojobetcasibomcasibom girişmatbetpusulabetcasibomcasibom giriş1xbetgrandpashabetgrandpashabetgrandpashabetgrandpashabetcratosroyalbetbetwoonjojobetGrandpashabetwbahis girişwbahisparmabet girişholiganbetjojobet girişparmabetparmabetkalebetpashagamingdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerromabetcasibomholiganbetmarsbahisKulisbetKulisbetbetkolikbetkolikKalebetbetkolikcasibomcasibom girişKocaeli EscorthiltonbetgalabetcasibomsekabetgrandpashabetRamadabetramadabetramadabetspincoLidyabetmatbetholiganbetgrandpashabet girişpusulabet girişmarsbahis giriş güncelholiganbet girişcasibommarsbahisgalabetbahiscasinopashagamingbetpiponitrobahisrealbahissonbahispusulabet girişmatbetimajbet girişcasibompusulabetcasibommatbetcasibomcasibom girişcasibom güncel girişcasibom güncelholiganbetbetpipo