我收到分段错误错误。谁能告诉我为什么?
#include <stdio.h>
#include <stdlib.h>
char sumArrays(int * arr1[], int * arr2[], int length, int count){
if(count == length){
return ' ';
}
else{
int sum = 0;
sum = *arr1[count] + *arr2[count];
char ch = '
ch = ch + (char)sum;
return ch + sumArrays(arr1, arr2, length, count+1);
}
}
int main(int argc, char * arr[]){
int length = 6;
printf("Enter the first row of 6 integers:");
int * arr1 = malloc(length * sizeof(int));
int * arr2 = malloc(length * sizeof(int));
int counter = 0;
int number = 0;
while(counter < length){
scanf("%d", &number);
arr1[counter]=number;
counter++;
}
counter = 0;
printf("Enter the second row of 6 integers:");
while(counter < length){
scanf("%d", &number);
arr2[counter] = number;
counter++;
}
char sum = sumArrays(&arr1, &arr2, length, 1);
free(arr1);
free(arr2);
printf("Their sums are : %c ", sum);
return 0;
}
我是 C 新手,对这门语言了解不多。我能够用 Java 编写程序并让它工作。任何帮助表示赞赏!
谢谢!
编辑:分段错误已修复,但现在它不打印总和的实际字符....