请问什么时候需要free,这个函数里应该怎么做?
#include <stdio.h>char *erjinzhi(char *zhizhen1, int s1);
int main(void)
{
char *a3;
printf("%s", erjinzhi(a3, 22));
return 0;
}
char *erjinzhi(char *zhizhen1, int s1)
{
zhizhen1 = malloc(sizeof(char) * 9);
int i1 = 0, i2 = s1, i3 = 0;
for (i1 = 0; i1 < 8; i1++)
{
zhizhen1[i1] = '0';
}
for (i3 = 8; i2 != 0; i2 = i2 / 2, i3 = i3 - 1)
{
if (i2 % 2 == 0)
{
zhizhen1[i3] = '0';
}
else
{
zhizhen1[i3] = '1';
}
}
return zhizhen1;
}
这个转二进制函数里malloc了内存,应该什么时候free?在哪里free?