Below is the rewriting of some string library functions in the C language. Now I will post the code to share with you,
If any errors are found, please give me more advice.
# Include # Include # Include
//////////////////////////////////////// ////////////// Convert character to uppercase.Const char * toupper (char * s){For (char * t = s; * t! = '/0'; t ++){If (* t> = 'A' * t * T-= 'a'-'A ';}Return s;}
//////////////////////////////////////// ////////////// Copies characters between buffers.//
Tags: HTTP ar OS SP problems BS HTML EF Linux
A very basic problem encountered during network programming today is the comparison of bcopy and memcpy.
First, describe the two functions:
Bcopy: http://man7.org/linux/man-pages/man3/bcopy.3.html
Memcpy: http://man7.org/linux/man-pages/man3/memcpy.3.html.
Pay special attention to the two parameters (the source
# Include Using namespace STD;Int main (){Int A [10];For (INT I = 0; I A [I] = I;Memcpy ( A [4], A, sizeof (INT) * 6 );For (I = 0; I Cout }
Very simple mini-program! But it is enough to achieve my goal: run the above Code GCC and then the result is: 0 1 2 3 0 1 2 3 0 1.Replace row 13th with: memmove ( A [4], A, sizeof (INT) * 6), run the GCC command again, and the result is: 0 1 2 3 0 1 2 3 4 5!Haha, there is a difference between the two. But this is
Yesterday I was asked a very basic C language question.Write the definition of u8 * memcpy (u8 * SRC, u8 * DST, size_t Len.
I thought I had to consider a lot of things, so I thought about a lot of things.Generally, it is written as void *, which is forcibly converted to an 8bit type. In fact, the unsigned char type is used here, and the forced conversion is no longer needed.
Whether SRC and DST are empty. I will use if to judge. If SRC is empty, a
Memory copy functions used in MEMCPY:C and C + +, the function of the memcpy function is to copy n bytes from the beginning of the memory address referred to by the source SRC to the starting position of the memory address referred to by the target dest.Function prototypes void* memcpy (void* dest, const void* SRC, size_t count)The function returns a pointer to dest:The difference between mencpy and memmove
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 content of the string, but also copies the end character of the string.
It is known that the prototype of the strcpy function is char * strcpy (char * DEST, const char * SRC );Memcpy provides general memory repl
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. If the source object is a string and the % s
Tags: c language simulation implement memcpy function in database; #include "C Language" "Face question" "pen question" simulation implement memcpy function in database
));Printf ("% s \ n", d );Strncpy (P, S, strlen (d ));Printf ("% s", P );Getchar ();Return 0;}------------------------------MemcpyPrototype: extern void * memcpy (void * DEST, void * SRC, unsigned int count );Usage: # include Function: copy count bytes from the memory area indicated by Src to the memory area indicated by DeST.Note: the memory areas specified by Src and DEST cannot overlap. The function returns a pointer to DeST.Example://
1. Void * memset (void * s, int C, size_t N)
Purpose: set the value of the first n Bytes of the memory space S to the value c.2. Example
#includevoid main(){char *s="Golden Global View";clrscr();memset(s,‘G‘,6);printf("%s",s);getchar();return 0;}
3. The memset () function is often used for memory space initialization. For example:
char str[100];memset(str,0,100);
4. Deep connotation of memset (): it is used to set all memory space to a specific character. It is generally used to initialize the d
Both memcpy and memmove () are library functions in C language. In the header file string. H, the function is to copy the memory content of a certain length. The prototype is as follows:
Void * memcpy (void * DST, const void * SRC, size_t count );Void * memmove (void * DST, const void * SRC, size_t count );
They play the same role. The only difference is that when the memory parti
); } printf (" char not found. \ n "); getchar (); return 0; }
Memcpy
Prototype: extern void * memcpy (void * DEST, void * SRC, unsigned int count );Usage: # include Function: copy count bytes from the memory area indicated by Src to the memo
Here memcpy and memmove function of the simulation implementation, need to use a null pointer to pass the parameter, after the forced type conversion to char type, with SIZE_T this macro accept offset offset, the simulation is implemented as follows:memcpy function:void* my_memcpy (Void*dst,const void*src, size_t count) {assert (DST); assert (SRC); void* ret = Dst;while (count--) {* (char* DST = * (char*) SRC;DST = (char*) DST + 1;src = (char*) src +
1 function prototypesvoid *memcpy (void *dest, const void *SRC, size_t n); 2 features copies n bytes from the starting position of the memory address referred to by the source SRC to the beginning of the memory address referred to by the target dest 3 required header files use # include You can use # include 4 return value The function returns a pointer to Dest. 5 Description The memory areas referred to by 1.source and Destin may overlap, but if th
. To overwrite the original string ' + ', add ' 3.strcpy ' at the end
Char *strcpy (char* strdest, const CHAR*STRSRC) {
assert (strdest! = nullstrsrc! = NULL);
char* address = strdest;
while (*strsrc! = ') ' {
*strdest = *strsrc;
strdest++;
strsrc++;
}
*strdest = ' + ';
return address;
}
Address overlap issues should also be considered if necessary 4.memcpy
First look at the explanation of the standard
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. If the source object is a string and the % s
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 content of the string, but also copies the end character of the string.
It is known that the prototype of the strcpy function is char * strcpy (char * dest, const char * src );
Memcpy provides general memory rep
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.