calloc内存分配的问题
写了一个函数如下
gboolean is_text_valid(const char *text, gchar **tmp){ //判断是否是有效输
int i, start, end, len; //入并截取有效部分
start = 0;end = 0;len = 0;
while(isspace(*(text + start)) && (text + start != NULL))
start++;
end+=start;
while(isalpha(*(text + end)) && (text + end != NULL))
end++;
if(!(len = end - start))
return FALSE;
*tmp = (gchar *)calloc(len, sizeof(char));
for(i = 0; i < len; i++)
*(*tmp + i) = tolower(*(text + start + i));
// *(*tmp + len) = '\000';
return TRUE;
}
*tmp = (gchar *)calloc(len, sizeof(char));
memset(tmp, 0, sizeof(char)*len ); //作下清零操作