SgtOVERKILL
SgtOVERKILL

Reputation: 319

C language how to fix my call function

I have added a void function and an int function. The void function works just fine but the int function will not work, I have been sure to include a return since it requires one. I think this has something to do with my call in the main. What am I missing or doing wrong here? Thank for the help in advance!

#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;
    }
}
} 

Upvotes: 1

Views: 184

Answers (2)

sjsam
sjsam

Reputation: 21965

The function declaration

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

doesn't match with function definition

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

Upvotes: 3

dbush
dbush

Reputation: 224387

The prototype of comp_vec doesn't match the definition.

The declaration:

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

The definition:

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

Change the declaration to match the definition, and you should be fine.

Upvotes: 2

Related Questions