(C/C++)ÖµµÃÑо¿µÄһЩº¯Êý
1. memcpyº¯ÊýµÄʵÏÖ
Ê×ÏȶÔÕâ¸öº¯Êý×öһЩ˵Ã÷¡£
#include <string.h>
void *memcpy(void *to, const void *from, size_t count)
º¯Êýmemcpy()´ÓfromÖ¸ÏòµÄÊý×éÏòtoÖ¸ÏòµÄÊý×鸴ÖÆcount¸ö×Ö·û¡£Èç¹ûÁ½Êý×éÖصþ£¬²»¶¨Ò庯ÊýµÄÐÐΪ¡£
ÔÚC99ÖУ¬toºÍfromÓÉrestrictÐÞÊΡ£
ÏÈÀ´¿´¿´Î¢ÈíµÄʵÏÖ£º
void * __cdecl memcpy (
void * dst,
const void * src,
size_t count
)
{
void * ret = dst;
#if defined (_M_IA64)
{
extern void RtlMoveMemory( void *, const void *, size_t count );
RtlMoveMemory( dst, src, count );
}
#else /* defined (_M_IA64) */
/*
* copy from lower addresses to higher addresses
*/
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
#endif /* defined (_M_IA64) */
return(ret);
}
ÔÙÀ´¿´¿´coreutilsÖеÄʵÏÖ£º
void *
memcpy (void *destaddr, void const *srcaddr, size_t len)
{
char *dest = destaddr;
char const *src = srcaddr;
while (len-- > 0)
*dest++ = *src++;
return destaddr;
}
ÔÙÀ´¿´LinuxÖÐʵÏÖ£º
void *memcpy(void *dest, const void *src, size_t count)
{
char *tmp = dest;
const char *s = src;
while (count--)
*tmp++ = *s++;
return dest;
}
¸÷ÖÖ¿¼ÂǵÄʵÏÖ
void* memcpy( void* dest, const void* src, size_t count )
{
if (count<0)
{
printf("Invalid count number !.\n");
return (void*)0;
}
if(src==NULL||dest==NULL)
return (void*)0 ;
if ((unsigned int)dest==(unsigned int)src)
{
printf("The source is equal with the destanation!.\n");
return dest;
}
char* d = (char*)dest;
const char* s = (const char*)src;
while(count--)
*d++ = *s++;
return dest;
}
¸ßÖÊÁ¿C++/C±à³ÌÖ¸ÄÏÀïÃæµÄʵÏÖ
void *memcpy(void *pvTo, const void *pvfrom, size_t size)
{
assert((pvTo != NULL) && (pvfrom != NULL)); // ʹÓöÏÑÔ
byte *pbTo = (byte *) pvTo; // ·ÀÖ¹¸Ä±äpvToµÄ
Ïà¹ØÎĵµ£º
#include<stdio.h>
const int A=10;
void main()
{
int group[A];
for(int i=0;i<A;i++)
{
group[i]=i+1;
}
int k=A;
int m=0;
int n=2;
int c=0;
int x;
do
{
&nbs ......
×î½üÒòΪÑо¿Ò»¸ö¶«Î÷£¬²¢ÇÒÔںܾÃÒÔÇ°¾ÍÏë°ÑpythonºÃºÃ¿´¿´¡£ÕýºÃÂú×ãÎҵĺÃÆæÐÄ¡£ÎÒÿÌìÉÏ°à×öµÃÓÎÏ·¶¼ÊÇÓÃlua£¬Ò²ÊÇÒ»ÃźÜÇ¿´óµÄ½Å±¾ÓïÑÔ¡£¿ÉÄÜÎÒ¸üϲ»¶pythonµÄËõ½øÇø·ÖºÍÃæÏò¶ÔÏó°É¡£ ½ñÌìֻдһ¸ö¼òµ¥µÄÀý×Ó¡£Ò»¸ö¼òµ¥µÄpython½Å±¾£¬¾ÍÒ»¸öº¯Êý£¬ÓÃC/C++È¥µ÷Ó᣿ÉÄÜÕâÒ²ÊÇ×÷Ϊ³ÌÐòÀ´Ëµ×î¹ØÐĵÄÒ»¼þÊ¡£ËùÒÔÎÒµÄpytho ......
// ·½°¸— Óŵ㣺½öʹÓÃC ±ê×¼¿â£»È±µã£ºÖ»Äܾ«È·µ½Ã뼶
#include <time.h>
#include <stdio.h>
int main( void )
{
time_t t = time(0);
char tmp[64];
strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A ±¾ÄêµÚ%jÌì %z",localtim ......
ÍøÓѹ۵ã:
(Ò»):
ÎÒÈÏΪºÜ¶àÈËûÓÐÀí½âlinus»òÕßmyanµÄÒâ˼£¬ÎÒ¾Ù¸öʵÀý¡£
ÎÒÃÇÏÖÔÚÒªÉè¼ÆÒ»Ì×ÍøÂ磿ͻ§¶ËÈí¼þ£¬ÎÒÃÇÒªÏÈ°ÑÐÒ鶨ºÃ£¬°Ñ½çÃæºÍºǫ́½»»¥Éè¼ÆÏëºÃ£¬°ÑÈÝ´íºÍ»Ö¸´ÏëºÃ£¬ÎÒÈÏΪÕâЩÊÇ×îÖØÒªµÄ£¬ÖÁÓÚ±àÂ룬ÓÃCÒ²¿ÉÒÔ±à³öÀ´£¬ÓÃC£«£«Ò²¿ÉÒÔ±à³öÀ´£¬ÉõÖÁÓÃJAVAÒ²Äܱà³öÀ´£¬¹Ø¼üÊÇÕû¸öÈí¼þµÄ¼Ü¹¹ÒªÇåÎú£¬Õ ......