[英]C language how to fix my call function
我添加了一個void函數和一個int函數。 void函數可以正常工作,但int函數不能工作,我已經確定要包含一個返回值,因為它需要一個返回值。 我認為這主要與我的通話有關。 我在這里想念或做錯了什么? 預先感謝您的幫助!
#include <stdio.h>
void multi_vec(int v1[], int v2[], int v3[], int n);
int comp_vec(int v1[], int v2[], int n);
int main(){
int n = 0;
int i = 0;
printf("Enter the length of the vectors: ");
scanf("%d",&n);
int v1[n];
int v2[n];
int v3[n];
printf("Enter the first vector: ");
for(i = 0; i < n; i++){
scanf("%d",&v1[i]);
}
printf("Enter the second vector");
for(i = 0; i < n; i++){
scanf("%d",&v2[i]);
}
multi_vec(v1, v2, v3, n);
printf("The multiplication of the vectors is: ");
for(i = 0; i < n; i++){
printf("%d",v3[i]);
printf(" ");
}
int compare;
compare = comp_vec(v1,v2,v3,n); //this is where I think I went wrong
}
void multi_vec(int v1[], int v2[], int v3[], int n){
int i;
for(i = 0; i < n; i++){
v3[i] = v1[i] * v2[i];
}
}
int comp_vec(int v1[], int v2[], int v3[], int n){
int i;
for(i=0; i < n; i++){
if(v1[i] != v2[i]){
printf("not the same");
return 0;
}
else{
printf("are the same");
return 0;
}
}
}
函數聲明
int comp_vec(int v1[], int v2[], int n); //3 param
與函數定義不匹配
int comp_vec(int v1[], int v2[], int v3[], int n){ // 4 param
comp_vec
的原型與定義不匹配。
聲明:
int comp_vec(int v1[], int v2[], int n);
定義:
int comp_vec(int v1[], int v2[], int v3[], int n){
更改聲明以匹配定義,就可以了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.