From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/FUNCTIONS/strcpy.html | 127 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 reference/C/FUNCTIONS/strcpy.html (limited to 'reference/C/FUNCTIONS/strcpy.html') diff --git a/reference/C/FUNCTIONS/strcpy.html b/reference/C/FUNCTIONS/strcpy.html new file mode 100644 index 0000000..2a15dbb --- /dev/null +++ b/reference/C/FUNCTIONS/strcpy.html @@ -0,0 +1,127 @@ +strcpy function + + + + + + +
+
+

strcpy function

+
+
+

+strcpy copies a string. This function will copy the bytes +stored at the location pointed to by 's2' to the location pointed to by 's1'. + +

+
+     	s1		s2
+	|		|
+	V		V
+        - - - -		- - - --	
+       | | | | |       |a|b|c|\0|
+        - - - -		- - - --	
+	^ ^		| |
+	| |		| |
+	 -|-------------  |
+	   ---------------
+
+ +
+
+Library:   string.h
+
+Prototype: char strcpy(char *s1, const char *s2);
+
+Syntax:	  
+	   char string2[20]="red dwarf";
+	   char string1[20]="";
+           strcpy(string1, string2);
+
+ +
+ +

Notes

+ +Dont forget that strings are terminated with a +'\0' so allow space for it... +

+There is another way to code the example above. Consider this piece of +code. +

+	main()
+	{
+	  char *string2="red dwarf";
+	  char *string1;
+
+	  string1=string2;
+	}
+
+ +'string2' is now a character pointer (only one byte) that points to a +storage location containing "red dwarf" (a +string constant). So +string1=string2; copies the address of "red dwarf" into +'string1'. This version of the code will execute quicker than strcpy +because less data is being moved around the system. + + +
+ +example program. +
+ +

See also:

+ + +strtok +
+ + +strncpy +
+ + +sprintf +
+ + +strcat +
+ + +strings +
+ + +memcpy Copy data between tow memory locations. +

+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + -- cgit v1.2.3-54-g00ecf