C语言如何修复我的调用函数

时间:2016-06-02 17:58:44

标签: c arrays function vector

我添加了一个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;
    }
}
} 

2 个答案:

答案 0 :(得分:3)

函数声明

int comp_vec(int v1[], int v2[], int n); //3 param

与功能定义

不匹配
int comp_vec(int v1[], int v2[], int v3[], int n){ // 4 param

答案 1 :(得分:2)

comp_vec的原型与定义不符。

宣言:

int comp_vec(int v1[], int v2[], int n);

定义:

int comp_vec(int v1[], int v2[], int v3[], int n){

更改声明以匹配定义,您应该没问题。