Nan*_*nik 2 c substring memcpy
我想试试C memcpy函数.我有这个代码:
char destination[40]; memcpy(destination, "My favorite destination is...", 11); printf(destination);
我想将前11个字母复制到目标数组.当我使用printf时,结果是"我最喜欢的2".为什么?
Ext*_*der 10
您在11个字符的末尾缺少NULL终止符 - > Printf只是打印内存中的任何内容,直到找到NULL终止符.
只需添加目的地[11] = 0;
那应该工作:)
归档时间:
14 年,3 月 前
查看次数:
2575 次
最近记录: