嗨我试图加入一个未定义大小的新数组中的整数数组(取决于前两个数组。但是当我运行代码时,它似乎停留在一个无限循环中。我做错了什么?Ps。数组应该在遇到-1 Ds时结束。
int
main (void) {
void join(int arr1[], int arr2[]);
int vectorA[11] = {8, 17, 29, 32, 33, 33, 77, 81, 90, 94, -1};
int vectorB[11] = {8, 17, 29, 44, 33, 33, 77, 81, 90, 94, -1};
join(vectorA, vectorB);
return 0;
}
void join(int arr1[], int arr2[])
{
int count=0, counter=0;
int i=0, j=0;
while(arr1[i]>-1)
count++;
while(arr2[j]>-1)
count++;
int tot[count];
for(i=0, j=0; ((arr1[i]>-1) || (arr2[j]>-1)); )
{
if(arr2[j]<0) {
tot[counter++]=arr1[i++];
}
else if(arr1[i]<0) {
tot[counter++]=arr2[j++];
}
else {
tot[counter++]=arr2[j++];
tot[counter++]=arr1[i++];
}
}
printf("the doubled array is : \n");
for(int i=0; i<count; i++)
{
printf("%d, ", tot[i]);
}
}