#include <stdio.h>
#include <conio.h>
#include <string.h>
void change(int *v[]) {
int tmp;
for (int i = 0; i < 10; i++) {
for (int j = i + 1; j< 10; j++)
if (*v[i] > *v[j]) {
tmp = *v[i];
*v[i] = *v[j];
*v[j] = tmp;
}
}
}
void main() {
int v[10];
for (int i = 0; i < 10; i++) {
printf("Enter the value for v[%d]: \n", i);
scanf("%d", &v[i]);
}
printf("The vector is: \n");
for (int i = 0; i < 10; i++)
printf("Value on the position %d is %d \n", i, v[i]);
change(&v[]); // I think here is the problem
printf("\n\n After function call, the vector is: \n");
for (int i = 0; i < 10; i++)
printf("Value on the position %d is %d \n", i, v[i]);
getch();
}
我需要排版一個向量,但我不知道如何將向量的值傳遞給一個函數。有人可以幫助我解決這個問題,並解釋我並讓我明白,這很重要。感謝你們 !在c中訂購一個向量
推薦閱讀任何C書或文本。有關函數,數組和指針以及如何傳遞它們的信息,請參閱部分。這比任何在這裏回答的人都更容易理解。這不應該花費太多時間。 – phoxis
您是否嘗試更改該行(您認爲該概率爲: 更改(v); 或更改(&v) –
C沒有「向量」,您的意思是_arrays_! – Olaf