Implementation of strcpy (), implementation of strcpy ()
I can see a blog that is more in-depth than what I usually understand. mark: Implementation of the strcpy Function
Here, we only understand what we usually understand. There are three key points:
1 // strcpy implement 2 3 char *
[C Language] Implementation of strcpy function, strcpy Function
Basic Content of the strcpy function:
Prototype Declaration: extern char * strcpy (char * dest, const char * src );Header file: # include # Include The running result is as follows:
When copying a string, I usually use the strcpy or strncpy function, of course, the memcpy function can also be implemented. So what's the difference between strcpy and memcpy?
Here is a piece of information I found (original address: http://www.cnblogs.com/stoneJin/archive/2011/09/16/2179248.html)
The difference between strcpy and memcpy
Let's take a look at an example first
char * strcpy (char * strdest,const char * strsrc) {
if (null==strdest) | | (NULL==STRSRC))
Throw "Invalid argument (s)";
char * strdestcopy = strdest;
while ((*strdestcopy++ = *strsrc++)!= ' ");
return strdest;
}
I suddenly thought of a question I had done before
Topic:The prototype of the known strcpy function is:char *
What are the differences between the strcpy and memcpy functions in C language? Below with me to introduce a simple, I hope you give more comments, welcome comments to correct errors.6.2 Strings and ArraysStrings are typically stored in a character array, such as the following STR definition:
Char str[] = "123456";
Here str is an array of characters, it holds a string "123456", because the string also has a Terminator "" ",
Difference between strcpy and memcpy, and between strcpymemcpy
Strcpy and memcpy are both standard C library functions, which have the following features.Strcpy provides string replication. That is, strcpy is only used for string copying. It not only copies the string content, but also copies the string Terminator. strcpy_s is safer!
It is known that the prototyp
The prototype of the known strcpy function is a char *strcpy (char *strdest, const char *STRSRC);Where strdest is the destination string, Strsrc is the source string.(1) Do not call the C++/C string library function, write the functionstrcpy Char *strcpy (char *strdest, const char *STRSRC);{ASSERT ((strdest!=null) (strsrc!=null)); 2 minchar *address = strdest; 2
message Oh!The next thing I want to share is my thoughts and methods of learning strcpy,strncpy,strcat,strncat,strcmp.First talk about strcpy,strncpy.In the main function, first define two string array char Dest[10];char src[]= "abcdef"; Copy the string from src to dest. The method is implemented by calling the function, passing in the main function two arrays, in the calling function with a pointer to rec
Implementation of C + + Common library function atoi,itoa,strcpy,strcmpC-language string manipulation functions1. String reversal-Strrev2. String copy-strcpy3. String conversion to integer-atoi4. String Length-strlen5. String connection-strcat6. String comparison-strcmp7. Count the number of vowel characters in a string8. Determine if a string is a palindrome1. Write a function to implement string inversionVersion 1-while Editionvoid Strrev (char *s){
The following programs:#include usingnamespace std; int Main () { char ch1[]; strcpy (CH1,"123456");}Error when compiling on VS2012:Error C4996: ' strcpy ': This function or variable could be unsafe. Consider using strcpy_s instead.In VS2010, there are numerous system function names appended with _s, such as scanf_s (), strcmp_s (), and so on. _s that this method is safe (safe), the original functio
Original address:
Http://www.cppblog.com/junfeng568/archive/2006/03/11/4022.html
memset is used to set all the memory space to a certain character, generally used to initialize the defined string to "or";
Example: Char a[100];memset (A, ' n ', sizeof (a));
Memset can easily empty a variable or array of a struct type.
Such as:
struct SAMPLE_STRUCT{Char csname[16];int iSeq;int itype;};
For variablesstruct Sample_strcut sttest;
In general, the method of emptying the sttest:
Sttest.csname[0]= ' "
Http://baike.baidu.com/view/1756792.htm#2
Function Introduction
Function Name: strrchr
Function prototype: char * strrchr (char * STR, char C );
Database: String. h
Function:Returns the position of the last occurrence of a character C in another string Str.(That is, to find the first occurrence position of character C from the right side of Str), and return all characters from this position in the string until the end of the string. If the specified character cannot be found, the function return
Conversion from: Implementation of strcpy Function
Code Implementation
#include View code
It is known that the prototype of the strcpy function is:
Char * strcpy (char * DST, const char * SRC );
Implement strcpy Functions
Explain why char * is returned *
If we consider how to implement
This article from: norcy https://www.cnblogs.com/chenyg32/p/3739564.html (respect for labor results, welcome to read the original, invasion and deletion)
It is known that the prototype of the strcpy function is:
Char * strcpy (char * DST, const char * SRC );
Implement strcpy Functions
Explain why char * is returned *
If we consider how to implement
1. strcpy function:As the name implies string copy function: Prototype: extern char *strcpy (char *dest,char *src);Function: Assigns a string that starts from the SRC address and contains a null terminator to the address space beginning with dest, returning dest (the address is stored as a new value after the copy).requirement: SRC and dest memory areas cannot overlap and dest must have enough space to acco
Transferred from: http://www.cnblogs.com/chenyg32/p/3739564.htmlThe prototype of the known strcpy function is:Char *strcpy (char *dst, const char *SRC);
Implementing the strcpy function
Explain why you want to return char *
If you consider the case of DST and src memory overlap, strcpy how to implement
The following knowledge points are scattered, often used in programming, make a note:1,memsetFunction prototype: void * memset (void * Dst, int Val, size_t size);Function: Sets the value of the first size byte of the DST that has opened up the memory space to a value of ValSuch as:memset (Header->wsa__messageid, 0, 100); Empty the contents of Header->wsa__messageid2,strcpyFunction prototypes: extern char *strcpy (char *dest,char *src);Function: Copies
length. Const intInt_size =4;int[] arr = {2,4,6,8,Ten, A, -, -, -, - }; Buffer.blockcopy (arr,3* Int_size, arr,0* Int_size,4*int_size);foreach(intValueincharr) Console.Write ("{0}", value);//The example displays the following output://8 in tenIi. strcpy Security Issues 2.1 using strcpy to copy stringsA simple scenario in which a string is copied into another string, and in the C language textbook, the long
Tag: String
Strcpy and memcpy are both standard C library functions, which have the following features:
1. strcpy provides string replication. That is, strcpy is only used for string copying. It not only copies the content of the string, but also copies the end character of the string.
The strcpy function is prototype:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.