谁帮我看下分配指针数组时 释放(free无法释放,卡在)
程序代码:
int my_memcmp(char *str1, char *str2) { for (int s1 = 0; *(str1 + s1); s1++) if (*(str1 + s1) > *(str2 + s1)) return 1; else if (*(str1 + s1) < *(str2 + s1)) return -1; return 0; } void sort_char(char *p_char[N],int n) { printf("%d\n", my_memcmp(p_char[0], p_char[1])); } int main() { char *p_char[N] = { NULL }; for (int i = 0; i < N; i++) { p_char[i] = (char *)malloc(sizeof(char) * N*N); if (p_char[i] == NULL) { printf("Allocate memory failure\n"); exit(1); } scanf("%s", p_char[i]); } sort_char(p_char, N); for (int i = 0; i < N; i++) { free(p_char[i]); p_char[i] = NULL; } system("pause"); return 0; }