我用 C 编写了这段代码,它适用于小输入和我能想到的所有测试用例。但是当一个大文件作为输入时,它会给出 SIGABRT 错误。有人可以解释一下原因吗?
#include<stdio.h>
#include<string.h>
void q_sort(char **numbers, int left, int right)
{
int l_hold, r_hold,temp;
char *pivot;
l_hold = left;
r_hold = right;
pivot = numbers[left];
while (left < right)
{
while (strcmp(numbers[right],pivot)>=0 && (left < right))
right--;
if (left != right)
{
numbers[left] = numbers[right];
left++;
}
while (strcmp(numbers[left],pivot)<0 && (left < right))
left++;
if (left != right)
{
numbers[right] = numbers[left];
right--;
}
}
numbers[left] = pivot;
temp = left;
left = l_hold;
right = r_hold;
if (left < temp)
q_sort(numbers, left, temp-1);
if (right > temp)
q_sort(numbers, temp+1, right);
}
int main()
{
int x,y,i,j;
int *arr;
char **str;
int *count;
while(1)
{
scanf("%d%d",&x,&y);
if(x==0 && y==0)break;
str =(char **)malloc(sizeof(char *)*x);
count=(int*)malloc(sizeof(int)*x);
i=0;
while(i<x)
{
str[i]=(char *)malloc(sizeof(char)*y);
scanf("%s",str[i]);
i++;
}
//sizeof(str)/sizeof(*str)
q_sort(str,0,x-1);// sizeof(str) / sizeof(char *), sizeof(char *),cmp);
i=0;
j=0;
arr=(int *)malloc(sizeof(int)*x);
while(i<x)
{
arr[j]=1;
while(i<x-1 && strcmp(str[i],str[i+1])==0)
{
i++;
arr[j]+=1;
}
j++;
i++;
}
for(i=0;i<x;i++)
{
count[i]=0;
}
i=0;
while(i<j)
{
count[arr[i]-1]++;
i++;
}
for(i=0;i<x;i++)
{
printf("%d\n",count[i]);
}
free(count);
free(arr);
for(i=0;i<x;i++)
free(str[i]);
free(str);
}
return 0;
}