C에서 배열 메서드에 쓰기를 시도했지만 예상 한 결과를 반환하지 않는 것 같습니다.C - 포인터 및 배열
How many numbers would you like to short?: 3
Checking for the i: 0: 1
Setting the number to temp 1
Checking for the i: 1: 2
Setting the number to temp 2
Checking for the i: 2: 3
Setting the number to temp 3
Setting the array2 to *array
0: 6487440
1: 0
2: 6480512
----------------------------------
Proces exited after 1.741 seconds with return value 3
그리고 이것은 코드
int array_size;
void getArray(int *array[]);
void printArray(int array[]);
void main() {
printf("How many numbers would you like to short?: ");
scanf("%d", &array_size);
int input[array_size];
getArray(&input);
printArray(input);
}
void getArray(int *array[]) {
int i, temp;
int array2[array_size];
for(i = 0; i < array_size; i++) {
printf("Checking for the i: ");
printf("%d: ", i);
scanf("%d", &temp);
printf("Setting the number to temp %d\n", temp);
array2[i] = temp;
}
printf("Setting the array2 to *array\n");
*array = array2;
}
void printArray(int array[]) {
int i;
for(i = 0; i < array_size; i++) {
printf("%d: %d\n", i, array[i]);
}
}
I scanf와 같은 시도하여 ("%의 D를"& 배열 * [I])이다에게 하지만 작동하지 않습니다.
내가 뭘 잘못하고 있는지에 대한 아이디어가 있습니까? 미리 감사드립니다.
'* array = array2;'를 쓰면 무엇을 할 계획입니까? –
이것을 컴파일하려고하면 경고가 표시되지 않습니까? 경고를 기본 수준으로 낮추더라도 gcc에 8 가지 경고가 표시됩니다. 먼저 수정하십시오. –
항상 텍스트를 표시하고 사진을 표시하지 않습니다. (당신을 위해 그것을 고쳤습니다.) – DevSolar