Passing pointers to structers

After a lot research, K&R C book +++ others, including WEB getting in to brain meltdown.
Problem is very simple, but can not get it compiled … so doing something stupid.
What I wish is: have global structures looking like this

typedef struct{
unsigned int seconds;		// RA values
unsigned int minutes;
unsigned int hours;
long total_seconds;		// RA time converted to seconds
long go_to_seconds;		// RA goto converted to seconds
}ra;
typedef struct{
unsigned int seconds;		// DE values
unsigned int minutes;
unsigned int hours;
long total_seconds;		// DE converted to seconds
long go_to_seconds;		// DE goto converted to seconds
}de;

Have universal function to display members of this structures so pass pointers to display structure members instead writing several display functions.

// ========== display time, universal function =====================
void display_time(int *ra)   // or other structure
{
	struct{
	unsigned int seconds;	
	unsigned int minutes;
	unsigned int hours;
	long total_seconds;
	long go_to_seconds;
	}pn;
pn=&ra;
		lcd_goto_xy(0, 1);	//LCD second row
		print_long((pn.hours/10)%10);	// hrs tens
		print_long((pn.hours)%10);
		print_character(':');
		print_long((pn.minutes/10)%10);	// tens of minutes
		print_long((pn.minutes)%10);
		print_character(':');
		print_long((pn.seconds/10)%10);	// seconds tens
		print_long((pn.seconds)%10);
}
//=================== end of display time ==========================

The above function does not compile … so I am doing something wrong …
After while got completely confused.
Please any C guru help …
Using gcc version 4.6.3 (GCC)

Thanks for your time … Kris

Hello, Kris.

The error that you received in your code probably occurred at this line:

pn=&ra;

The reason is that you were trying to assign an int ** (a pointer to an integer pointer) to your struct, which are two incompatible data types. I am not quite sure why you have multiple globally defined structures containing the same data type members in your code. It might be easier for you to define one struct and declare multiple instances of it. A possible solution is shown below:

typedef struct {
   unsigned int seconds;
   unsigned int minutes;
   unsigned int hours;
   long total_seconds;
   long go_to_seconds;
} time_info;

time_info ra;			// ra & de are global struct objects of type time_info
time_info de;

void time_display(time_info *ptime){
  // dereference the pointer to get struct data members
  print_long( (ptime->hours / 10) % 10);
  print_long(ra.minutes / 10);	// access data members of global variable
  ...
}

void example_usage() {
  ra.seconds = 3;		// directly write to ra
  ra.hours = 1;
  ...
  de.hours = 2;
  ...

  time_display(&ra);		// pass variable ra as pointer (&) to function
  time_display(&de);
}

I hope this helps!

- Amanda

Thanks Amanda
You are genius …
To answer your question - What I am doing is SV328 based telescope GoTo controler. So far pieces of program that drive motors ( 2 stepper and 2 servos ) done and tested. That was easy part …
The challange is to make human interface using 3 buttons on 2 lines of LCD and write quite (?) involved math that calculates motors vs stars movements/positions.
The structures I’ve asked in my question are part of math routines. Doing it in Pascal or Fortran is easy … but doing it in fancy assembler :slight_smile: the C lingo is another story and on 8 bit machine.

The project will be shared later on my WEB site, including film showing the contraption in action and as well in Community projects.

Thanks Amanda for your time … kind regards Kris

I am glad to hear that the code was helpful to you, and appreciate that you explained your code further. We look forward to hearing about your completed project on the forum; thank you for sharing it.