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

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 );*/
  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;

thanks in advance! :)

Recommended Answers

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).
You can't ask people to do your homework ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.