Global Function not returning the correct values

Bruno Stühler

I'm trying to compile the first non zero value of a vector, using a global function. But as I compile, it returns the original value k1=k2=1, when it's supposed to be k1=0 and k2=2. No? My code looks like this:

#include<math.h>
#include<stdlib.h>

int primeiro(float vec[], int f)
{
  f=0;

    while(vec[f]==0)
    {
     f++;
    }

 return f;
}


int main()

{
float poli1[4]={1,2,3,4}, poli2[4]={0,0,5,6};
int k1=1, k2=1, i;

printf(" \n");

for(i=0; i<4; i++)
  {
     printf("%g\t", poli1[i]);
  }

printf("\n \n");

for(i=0; i<4; i++)
  {
     printf("%g\t", poli2[i]);
  }

printf("\n \n");

primeiro(poli1, k1);
printf("%d \n", k1);
primeiro(poli2, k2);
printf("%d \n", k2);
                
}```
ikegami

You never change k1 and k2, so they have their original value.

Maybe

primeiro(poli1, k1);
primeiro(poli2, k2);

was meant to be

k1 = primeiro(poli1, k1);
k2 = primeiro(poli2, k2);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

JavaScript function returning undefined, but logging to the console gets correct values?

R function not returning values

PHP function returning anonymous function with use / global

tfidf.transform() function not returning correct values

PHP bitwise operations not returning correct values

PATINDEX and SUBSTRING not returning correct values

GeoHash Function not returning correct result

Python 'str.contains' function not returning correct values

oracle function not returning correct value

Recursive program printing but not returning correct values

Lua function not returning the values

Visual Studio not returning correct C float values

Like statment not returning correct values

Returning Values in javascript function

Is there a global keyword similar to C's "Return" for returning values from a VBA function?

loop through array not returning correct values

ENCRYPTBYPASSPHRASE and DECRYPTBYPASSPHRASE is not returning correct values

Insert not Returning Correct Values

Returning values outside of a function

Returning 2 values in a function

The prime function is not returning correct result

Replace function not returning correct values

Why isn't my function returning the correct Key of the values?

natrsort function not returning values

Function is not returning any values

Why is my blur function in CS50's filter(less) (PSET 4) not returning the correct values?

Scipy BasinHopping not returning correct global minima

Powershell function to check input and return datatype is not returning correct values

Bisection function returning the correct values with only some functions