String Cloning

String Copy Functions

Coders, programmers and all the rookies who are new to programming always use string copy functions.As the name suggests, these are standard library functions which copies one string into other.Here we'll discuss two standard functions:


  • strcpy() : which copies the whole string into another
  • strncpy() : which copies a part of one string into another




Syntax



The first function takes 2 arguments:

strcpy(char *target, char *source) ;




The second function takes 3 arguments:

strncpy(char *target, char *source, int n) ;

Here "n" represents the number of characters which are to be copied into another string




Working Example




#include

#include
int main()
{
int n ;
char source[25], target[25] ;
strcpy(source, "fetch-info.blogspot.com") ;
strncpy(target, source, 10) ;
printf("Source String: %s\n", source) ;
printf("Target String: %s",target) ;
return 0 ;
}


OUTPUT

Source String: fetch-info.blogspot.com
Target String: fetch-info

Comments

Popular posts from this blog

Search box for blog or website

Image Search Engine Using Python

Cordova viewport problem solved