C语言 malloc strlen 一起使用时的注意事项

mac2024-05-12  34

 p = malloc(strlen(str)+1) 

字符串实际占用大小比strlen求出的字符数多1个(字符串结尾的0也要占用空间),所以需要申请strlen(str)+1个单元

最新回复(0)