分段错误(核心已转储)
我尝试制作开始和结束指针。将变量放在不同的位置。
int find_subarray(int a[], int size_a, int b[], int size_b, int* start, int* end);
int main()
{
int size_a;
int size_b;
int start = 0;
int end = 0;
/*Enters length of first array*/
printf("Enter the length of the first array: ");
scanf("%d", &size_a);
/*sets first array to size_a */
int a[size_a];
int i;
printf("Enter the elements of the first array: ");
for(i = 0; i < size_a; i++)
{
scanf("%d", &a[i]);
}
/*Enters length of second array*/
printf("Enter the length of the second array: ");
scanf("%d", &size_b);
/*sets second array to size_b */
int b[size_b];
printf("Enter the elements of the second array: ");
for(i = 0; i < size_b; i++)
{
scanf("%d", &b[i]);
}
find_subarray(a, size_a, b, size_b, start, end);
if(end != size_b)
{
printf("Output: The secound array is not a subarray of the first array.\n");
}else
{
end += start;
printf("Output: The second array is a subarray of the first array.\n");
printf("The subarray starts at index %d and ends at index %d.\n", start, end);
}
return 0;
}
int find_subarray(int a[], int size_a, int b[], int size_b, int *start, int *end)
发出警告:传递'find_subarray'的参数6会使指针从整数转换而无需强制转换 如果运行,它将执行第一部分直到发布的最后一行。然后进行分段错误(核心已转储)