``````#include<stdio.h>
#include<math.h>

#define min(a,b) (((a)>(b))?(b):(a))
#define abs(a)   (((a)>(-(a)))?(a):(-(a)))

void convert( int bod, int *x, int *y, int *z )
{
int a;
int b;
int c, str, zb;
if( bod==1 )
{
*x=0;
*y=0;
*z=0;
return;
}
a=(bod-2)/6;
b=(-1.0+sqrt(1+8*a))/2.0;
c=bod-1-3*b*(b+1);
++b;
str=(c-1)/b;
zb=c-str*b;
switch( str )
{
case 0: *x=-zb; *y=-b; break;
case 1: *x=-b; *y=zb-b; break;
case 2: *x=zb-b; *y=zb; break;
case 3: *x=zb; *y=b; break;
case 4: *x=b; *y=b-zb; break;
case 5: *x=b-zb; *y=-zb; break;
}
*z=*x-*y;
return;
}

int main(void)
{
int a, b, ax, ay, az, bx, by, bz, x, y ,z;
int pom;
scanf( "%d %d\n", &a, &b );
while( a!=0 || b!=0 )
{
convert( a, &ax, &ay, &az );
convert( b, &bx, &by, &bz );
/*  printf( "%d %d %d\n", ax, ay, az );
printf( "%d %d %d\n", bx, by, bz );*/
x=abs(ax-bx);
y=abs(ay-by);
z=abs(az-bz);
pom=min(x+y,x+z);
printf( "The distance between cells %d and %d is %d.\n", a, b, min(pom,y+z) );
scanf( "%d %d\n", &a, &b );
}
return 0;
}``````

## All 2 Replies

This is quite straightforward. Your only problem is that Java doesn't have pointers, so you need another way of passing the values to be converted by reference.
What you need to do is to put the arguments to the convert function into a class:

``````class convertArgs {
public int bod;
public int x;
public int y;
public int z;
}``````

Then rewrite the convert function to take one of these objects as its sole argument (call it args).
When you want to set a variable, you would then say:

``args.x = 0;``

rather than:

``*x = 0;``

In your main function, you just construct one of the convertArgs objects and populate it with the values you want before passing it to convert.
You can then read the converted values back out of it.

You have to learn how to do it. Java and C are similar (no pointes in C).