Filling array in a function

Sorry but I have to ask here again.
I have an char array, char result[8];
on the other hand I have, int value;

snprintf(result, sizeof(result), “%d”, value); works fine.
result is then printed on an lcd

but now I have some calculation to get the int value based on different sources and different target. So I like to have something like this

char result[8|;
int value1;
int value2;

void convert(result, int z)  // should fill result with ASCII equivialent of z
{
  z = z *2;  // calculation example
  snprintf(result, sizeof(result), "%d", z); 
}

void setup()
{
...
}

void main{}
{
   convert( result, value1);
   lcd.print(result);
   convert(result,value2);
   lcd.print(result
}

I tried a lot of things and did some hours search a solution, but did not get passing the array (that means a pointer) to the convert function.
Can someone help me please. I know I am still learning pointers and references and got it with int and so on, but not with char arrays.
Thanks

Rainer

result has no type in that function.

If you want to pass a character buffer, it needs to be of type char*.

Notice that you cannot use sizeof(result) then to get the original size of the buffer – once it has been passed into the function as char*, the information of many bytes that buffer was big is lost, and sizeof will return the size of that variable type, aka the size of a pointer. The size of that depends on the architecture, for AVR it’s 16-bits and for ARM and XTensa it’s 32-bits. The length needs to be explicitly passed into the function to be able to use it correctly. If you not design a function that way and just assume the buffer has a certain length, it is very easy to produce a buffer overflow error. Note that for the size of something, the type size_t from stddef.h is commonly used. To calculate the length of the buffer you can use sizeof(), you just need to make sure that it’s at the right scope where the compiler sees it as an array of known size, not as a pointer.

Also something note is that your function’s argument is of the same name as a global variable, result. Local variables will overshadow global ones, so this is fine, but beginner programmers may be confused as to which exactl variable they’re now referring to.

This is invalid code. After a function name, the params (or none) must be enclosed in (), not {}. Also, if you declare a main() function in your sketch when using the Arduino framework, you will be overwriting the Arduino frameworks internal main() function, which is bad.

So you should be writing it as

#include <string.h>
#include <stdio.h>
//..other includes..

char result[8|;
int value1;
int value2;

void convert(char* buf, size_t len, int z)  // should fill result with ASCII equivialent of z
{
  z = z *2;  // calculation example
  snprintf(buf, len, "%d", z); 
}

void setup()
{
...
}

void some_main_func()
{
   convert(result, sizeof(result), value1);
   lcd.print(result);
   convert(result, sizeof(result), value2);
   lcd.print(result
}

Thank you very much. By the way “void main{}” was just a mistype, the code was not cut and paste as its more complex, i just would give an example to the problem.
I really appreciate the good and quick help here