# Include
# Include
# Include
# Include
// Memcpy: copy by byte
Prototype: extern void * memcpy (void * dest, void * src, unsigned int count)
// Function: copy count bytes from the memory area indicated by src to the memory area indicated by dest;
// Same as strcpy
Void * memcpy_su (void * dest, void * src, unsigned int count)
{
Assert (dest! = NULL) (src! = NULL ));
Char * bdest = (char *) dest;
Char * bsrc = (char *) src;
While (count --> 0)
The place that strcpy didn't take into account
Original posted Address:Http://eparg.spaces.live.com/blog/cns!59BFC22C0E7E1A76!1498.entryOriginal Paste Time:2006-08-16Original Paste Author:EpargThe discussions of the year were in:
Http://eparg.spaces.live.com/blog/cns!59BFC22C0E7E1A76!533.entry
When Http://eparg.spaces.live.com/blog/cns!59BFC22C0E7E1A76!875.entry first considered the performance of strcpy, o
Header file:
#include
To define a function:
char * strdup (const char *s);
Function Description: StrDup () will first use MAOLLOC () to configure the same size as the parameter s string, and then copy the contents of the parameter S string to the memory address, and then return the address. The address can finally be released using free ().
Return value: Returns a string pointer to the copied new string address. Returning NULL indicates insufficient memory.
Example
Tag: print BSP Match color img display Add div addressThe source of the problem is a test code that you write yourself:#include using namespacestd;intMain () {Chara[1]; a[0] ='a'; a[1] ='b'; Charb[1]; b[0] ='C'; b[1] ='D'; strcpy (A, b); cout"after copy: a[0] ="0]"a[1] ="1]Endl; cout"after copy: b[0] ="0]"b[1] ="1]Endl; return 0;}After that, the value of the two string output is not imaginary:"After copy: a[0] = c A[1] = dAfter copy: b[0] = c B[1]
String.h:C language inside the function definition of the character array header file, commonly used functions have strlen, strcmp, strcpy and so on, in more detail can be in the Include folder to view the file.The%c format corresponds to a single character, and the%s format corresponds to a stringchar * strcpy (char *strdest,const char *strsrc){assert ((strdest!=null) (strsrc!=null)); Char *result=strdest
The strcpy () function was suddenly used todaySochar* A = "ABCDEFG";char* B = "GGGG";strcpy (A, b);Compile pass, but run unexpectedly directly ended, error;Why is it?Because char * A = "ABCDEFG";"ABCDEFG" This is a const property, then it exists in the static storage area, a pointer to the static store, but cannot change its valueSo you can't use the strcpy funct
According to cphj, the most frequently asked questions, and the opinions of many netizens. I have summarized the following:Most people agree to the following statement: the individual style is a little different.Char * strcpy (char * DEST, const char * SRC){Assert (null! = DEST );Assert (null! = SRC );
Char * TMP = DEST;While ('/0 '! = (* TMP ++ = * SRC ++) // it is necessary to compare * TMP because it is not a Boolean value.
;Return (DEST );}
The de
method of clearing sttest is as follows:Sttest. csname [0] = '/0 ';Sttest. iseq = 0;Sttest. itype = 0;
Memset is very convenient:Memset ( sttest, 0, sizeof (struct sample_struct ));
If it is an array:Struct sample_struct test [10];ThenMemset (test, 0, sizeof (struct sample_struct) * 10 );
If you have doubts about this problem, it is not about the function, but about the difference between MEM and Str.Mem is a piece of memory. Its length must be remembered by yourself.STR is also a piece of memo
Strcpy and memcpy have the following three differences.
The copied content is different. Strcpy can only copy strings, while memcpy can copy any content, such as character arrays, integers, struct, and classes.
The replication method is different. Strcpy does not need to specify the length. It ends with the string Terminator "/0. Memcpy decides the copy Length Ba
The difference between these functions is that the implementation functions and the operation objects are different.The strcpy function operates on a string to copy the source string to the target string.Objects operated by the snprintf function are not limited to strings: although the target object is a string, the source object can be a string or any basic type of data. This function is mainly used to convert (string or basic data type) to a string.
The difference between these functions is that the implementation functions and the operation objects are different.
The strcpy function operates on a string to copy the source string to the target string.
Sprintf function operation objects are not limited to strings: although the target object is a string, the source object can be a string or any basic type of data. This function is mainly used to convert (string or basic data type) to a string.
. Assume that the characters in front of the string on the two are always equal, like "disk" and "disks", the first four characters are the same, and then the fifth character is better than the delimiter, the first string "disk" has only the terminator '/0', And the last string "disks" has 'S ', the '/0' ASCII code is less than the 's' ASCII code, so the result is obtained. Therefore, no matter what the two strings are, the strcmp function can obtain the result at most until one character string
1. First, let's look at the implementation of the strcpy function in the kernel for one year:
The parameters of the strcpy () function are pointers to the destination string and the source string,
The function is to pass the source string to the pointer that stores the destination string.
Char * strcpy (char * DEST, const char * SRC){// TMP stores the first ad
strcpy Prototype declaration: extern Char *strcpy (char* dest, const char *SRC);header file: #Include
function:Copy the string that starts with the SRC address and contains a null terminator to the address space starting with dest
Description:The memory regions referred to in SRC and dest cannot overlap and dest must have enough space to hold the SRC string.
Returns a pointer to Dest.
function Implementa
The functions of the strcpy_s and strcpy () functions are almost the same. The strcpy function, like the Get function, has no method to guarantee a valid buffer size, so it can only assume that the buffer is large enough to hold the string to be copied. This leads to unpredictable behavior when the program is running. These unpredictable behaviors can be avoided by strcpy_s.This function can be used with tw
The prototype of the string function is char * strcpy (char * strdst, const char * strsrc)
Char * strcpy (char * strdst, const char * strsrc) // use const to indicate that the original string cannot be changed. In addition, use const to indicate that * strscr is the input parameter.
{
Char * address = strdst; // Save the first address of the target string, because the strdst pointer is moving next, not poi
Implementation of strcmp, strcpy, and strcat functions in C language. C language is the foundation of a programmer and must be paid attention.
Char * strcat (char * DST, const char * SRC) {char * CP = DST; while (* CP) CP ++; /* Find end of DST */while (* CP ++ = * SRC ++ ); /* Copy SRC to end of DST * // until '\ 0' return (DST);/* return DST */} Char * strcpy (char * DST, const char * SRC) {char * CP =
Function prototype:
Char * strcpy (char * DEST, const char * Source );
Parameter Declaration: DEST points to the first address of the target string, and source points to the first address of the source string.
Return Value: return the first address of the destination string DeST. The purpose is to implement chained expression, as shown in figure
Int Len = strlen (strcpy (DEST, "hello "));.
Function: co
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.