spirntf 和 memcpy

来源:互联网 发布:名侦探柯南主线知乎 编辑:程序博客网 时间:2024/06/11 21:08

// 仅为笔记

 

sprintf和memcpy对字符数组的操作:

char str[125];

char str1[125];

sprintf( str, "%s", "I love c++!");

 

memcpy( str1, "I love c++!", strlen("I love c++!"));

str1[strlen(str1)] = '\0';

使用sprintf的好处:不需要对数组进行初始化.

 

memcpy可以直接对结构进行操作:

tm tmLast;

tm tmNew = *localtime( &time(NULL) );

memcpy( &tmLast , &tmNew , sizeof(tm) );

或者

tmLast = tmNew;

原创粉丝点击