## Function doesn't return right array's values

I've started learning functions in C.

I have a task to convert numbers from imperial to metric, which are contained in the 2d Array.

**Array:**

{1300, 0} [0][0] [0][1] {2198, 0} [1][0] [1][1] {4199, 1} [2][0] [2][1] {2103, 0} [3][0] [3][1] {3104, 1} [4][0] [4][1] {1093, 1} [5][0] [5][1] {3204, 0} [6][0] [6][1]

So I am calling function with `double`

return `SortedArray[DATA_ROWS] = find_function(MixedData);`

**find_function logic:**

0 is an indicator of the metric system value and 1 is an indicator of imperial system value,
`i`

is a row indexer and `j`

is a column indexer.

So when `for`

cycles find out that column value is 0 or 1 they save [j-1](an actual value that we need) into `SortedArray`

.

It also converts value if finds out that column value is 1 `SortedArray[i] = MixedData[i][j-1]*CONSTANT;`

Just for a check, I did `printf`

to see if values are correct and correctly converted if needed.
I got this output:

1300.00 2198.00 1301.69 2103.00 962.24 338.83 3204.00

So, seems like correct, but in Task I have another task - use 2 functions to solve this task.
I've decided to make another function, which will `sum`

all values in `SortedArray[DATA_ROWS]`

and then calculate `avg`

- average.
Then print them out.
And here comes the problem.

Calling function with no return `total_AVG(SortedArray);`

with copied array `SortedArray[DATA_ROWS]`

Just to check made a `printf`

and got this:

-1.#R 0.00 0.00 0.00 0.00 0.00 0.00

It seems like my `SortedArray[DATA_ROWS]`

did not copy into the second function `total_AVG`

**Pointers are coming in the next task, so according to task's timeline I can't use them**
*
(and even if I could, I have no idea how to use them still)*

Can you please tell me, what I am doing wrong.

**NB:**
Some comments and variables, which are not used just old ones, when I tried to correct my code.
And also I only need to understand why `SortedArray[DATA_ROWS]`

did not copy into second function `total_AVG`

. All further logic will be corrected after solving this problem.

Thank you! And sorry for broken English!

**CODE:**

#include <stdio.h> #define DATA_ROWS 7 #define DATA_COLS 2 #define CONSTANT 0.31 #define MAX 3 double find_function(int MixedData[DATA_ROWS][DATA_COLS]); void total_AVG(double SortedArray[DATA_ROWS]); int main(void) { int i; double SortedArray[DATA_ROWS]; int MixedData[DATA_ROWS][DATA_COLS] = { {1300, 0},//[0][0] [0][1] {2198, 0},//[1][0] [1][1] {4199, 1},//[2][0] [2][1] {2103, 0},//[3][0] [3][1] {3104, 1},//[4][0] [4][1] {1093, 1},//[5][0] [5][1] {3204, 0}};//[6][0] [6][1] SortedArray[DATA_ROWS] = find_function(MixedData); total_AVG(SortedArray); return 0; } double find_function(int MixedData[DATA_ROWS][DATA_COLS]) { // imperial numbers from source array "mixedData" are 4199,3104,1093; int i,j; // indexers double SortedArray[DATA_ROWS]; // 7 rows, each row suppose to contain only metric values // That means, if second for cycle with j indexer finds 0, it will contain j-1 value for example 1300 in SortedArray // If it finds in second for cycle with j indexer 1, it will converte the value from imperial to metric for example 4199*0.31 /* {1300, 0} [0][0] [0][1] {2198, 0} [1][0] [1][1] {4199, 1} [2][0] [2][1] {2103, 0} [3][0] [3][1] {3104, 1} [4][0] [4][1] {1093, 1} [5][0] [5][1] {3204, 0} [6][0] [6][1] */ // Probably problem in "double SortedArray and int MixedData" for(i=0;i<DATA_ROWS;i++) { for(j=0;j<DATA_COLS;j++) { if(MixedData[i][j]==0) { SortedArray[i] = MixedData[i][j-1]; } else if(MixedData[i][j]==1) { SortedArray[i] = MixedData[i][j-1]*CONSTANT; } } } for(i=0;i<DATA_ROWS;i++) { //total += SortedArray[i]; printf("%.2lf\n", SortedArray[i]); } return SortedArray[DATA_ROWS]; } void total_AVG(double SortedArray[DATA_ROWS]) { double avg,total; int i; for(i=0;i<DATA_ROWS;i++) { printf("%.2lf\n", SortedArray[i]); } //avg = total/DATA_ROWS; //printf("Total by every worker: %.2lf\n",total); //printf("In average by every worker: %.2lf", avg); return; }

**Showing that a function doesn't exist,** First solution: Notice f′(0)=−1, take ϵ=1/2, then there is δ>0 so that if x∈(−δ,δ) then f(x)−f(0)x−0∈(−3/2,−1/2). In particular f(x) has a different sign than x,� The TRIM function removes the extra regular spaces between words so that the statement appears normally in the worksheet Given the order-of-operations logic of Excel formulas, the formula calls the SUBSTITUTE() function and tell it to replace every occurrence of CHAR(160) — the non-breaking space — with a standard space, CHAR(32), contained

You cant use arrays like this

return SortedArray[DATA_ROWS]; SortedArray[DATA_ROWS] = find_function(MixedData);

You can pass it as parameter to function. like below.

find_function(MixedData, SortedArray); void find_function(int MixedData[DATA_ROWS][DATA_COLS], double SortedArray[DATA_ROWS]) { // Dont define, use itt from parameter // double SortedArray[DATA_ROWS]; // ... // Dont need to return. // return SortedArray[DATA_ROWS]; }

**Function doesn't exist in this service,** Problem. Serverless Framework is complaining that it cannot find a Lambda function with the specified name. Solution. Here are a few things to check if you are� I think @amitchandak is right, it's because of regional settings. My guess is that you don't have standard list and decimal separator, and they are both set to "," (I strongly recommend changing it, especially if you work with csv files), similar to the post here:

The function you've defined is:

double find_function(int MixedData[DATA_ROWS][DATA_COLS]) { }

It's return type is `double`

whereas you're trying to return an array, assays can't be returned liked nor can be assigned.

return SortedArray[DATA_ROWS];

Here you're trying to access the element which is equal to length, it's wrong. What you can do is, pass array as function parameter (or as a pointer) and return void. i.e:

void find_function(int MixedData[DATA_ROWS][DATA_COLS], double* SortedArray) { /*...*/ }

or you may use dynamic memory allocations.. in case you want to return the base address from the function.

**If a function doesn't return a value, the word ______ will appear as ,** Solved: If a function doesn't return a value, the word ______ will appear as its return type. - Slader. Case Number 2: The Formula Doesn't Update After Changes. You have a formula that you know you have entered correctly, but when you change the formula, or change the values of its dependent cells the formula continues to show the old value.

**Code Inspection: Function doesn't return a value on all code paths ,** Code Inspection: Function doesn't return a value on all code paths. Last modified: 08 May 2020. This code inspection warns you that a procedure has at least� Unfortunately, when you combine text and formatted numbers, like dates, times, currency, etc., Excel doesn’t know how you want to display them, so it drops the number formatting. This is where the TEXT function is invaluable, because it allows you to force Excel to format the values the way you want by using a format code , like "MM/DD/YY

**Why fill function doesn't work? - MATLAB Answers,** Why fill function doesn't work?. Learn more about fill MATLAB. IFS function is only available for Office 365 subscribers, it came to Excel with January 2016 updates for Office 365. Follow the below link: IFS Function . Make sure that you have Office 365 subscription with version 1601 (Build 6568.2025) and above!

brew tap azure/functions brew install azure-functions-core-tools@3 # if upgrading on a machine that has 2.x installed brew link --overwrite azure-functions-core-tools@3 v2.x brew tap azure/functions brew install azure-functions-core-tools@2 If you don't plan to use extension bundles, install the .NET Core 3.x SDK for macOS.

##### Comments

`SortedArray[i] = MixedData[i][j-1];`

you access invalid location when`j=0`

.- And
`SortedArray[DATA_ROWS] = find_function(MixedData);`

here too. - Again
`return SortedArray[DATA_ROWS];`

here too. `SortedArray[DATA_ROWS] = find_function(MixedData);`

->`double result = find_function(MixedData);`

. Your find function should return a single double. Most of your confusion comes from your attempt to "return arrays". You can't do that in C. You need to pass arrays by pointers. I'd advise stepping back from 2D arrays and study how arrays decay to pointers, and how that happens when you pass an array as function parameter.`SortedArray[i] = MixedData[i][j-1];`

you access invalid location when`j=0`

* I have if else cycle for chechking for imperial numbers marked as 1, when j=1 So if I am not mistaken when j = 0 I have for example 1300 value. And when j=1, it's either 0 or 1.`if`

it's a 0, just save previous value j-1 = j = 0, which is 1300 into array`else if`

it's a 1, just save previous value j-1 = j = 0, which is 1300 into array, but first multiply by`CONSTANT`

- Thank you for the fast response. Pointers are in the next lecture and next Tasks, so theoretically I can't use them right now. But this part helped me a lot: Further, with double SortedArray[DATA_ROWS]; you cannot return a locally declared array from a function. When the function returns, the function stack (containing your array) is destroyed (released for re-used). So I can use only a variable not array, to save data(SortedArray) from find function?
- You can just stick the array notation back in as parameters instead of the pointer notation I used. They are the same C11 Standard - 6.3.2.1 Other Operands - Lvalues, arrays, and function designators(p3) I have now confirmed the output -- it is correct. Remove the (duplicate) printing of numbers from
`find_function`

also make your`j`

loop`for (j=1;j<DATA_COLS;j++)`

and you are done. Now if you just use`qsort`

on`SortedArray`

after you call`find_function`

-- you would really have a`SortedArray`

. - Thanks! Yea, the main problem was only to receive this SortedArray.
- Thank you! Like from the previous answer I should give SortedArray[DATA_ROWS] from main function as a parameter to find_function because I can't contain data from it in array. And also I can't return locally declared array from function.