2-1 malloc字符串(p28)

无论在什么时候执行这样一条语句 malloc(strlen(str)) 基本上可以断定它是错的,因为字符串处理函数一般都包含一个额外空间,用于容纳 '\0' 字符

正确应是 malloc(strlen(str) + 1)

Last updated

Was this helpful?