Saturday, May 8, 2010

C වලින් String copy කිරීම

#include<stdio.h>
#include
<string.h> /* strcpy() function එක සදහා*/

main(){
char text1[20] = " Mahinda"; /* string buffer */
char text2[20] = " Ranil "; /* string buffer */

printf (" Original string contents are (ඔරිගිනල් text එක) -> %s\n", text1);

/* text2 හි ඇති වචනය text1 ට copy කරන්න.( Copy text2 into text1 ) */
strcpy(text1, text2);
printf (" now string contents are ->%s\n", text1);
/* If text1 is smaller that text2 it will probably overwrite something! */

strcpy(text1, "Fonseka");
printf (" final string contents are: ->%s\n", text1);

}




----------------------------------------------------------------------------------------------------
as@as-desktop:~/Documents/C_CODE$ gcc stringCopy.c
as@as-desktop:~/Documents/C_CODE$ ./a.out
######Out Put (gcc) ########################

Original string contents are (ඔරිගිනල් text එක) -> Mahinda
now string contents are -> Ranil
final string contents are: ->Fonseka

################################


No comments:

Post a Comment