Using JNI to talk to C struct

I barely understand what a struct is other than sorta like a class in java. I want to use processing and java to provide the input and then get the result back to java. I went to this link and found some code I want to use: celestial navigation I tried the code and like how simple it is to use. I know its out of date, but I can fix that eventually. I then went to here: https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html and learned a little about JNI . I also found an example of using JNI with processing: https://processing.org/discourse/beta/num_1147602703.html

I got that example to work!

The problem I have is what do I put in my java class if I want to use this C struct. I know I have to declare static native, etc. but I’m lost with what to do with a struct.

Here’s the C struct:

struct COMPLX getlatlng(struct COMPLX *x,int prompt)
{
	int i = 0;
	double a;
	if(prompt)
	{
		if(!comline)
			myputs(
		"Enter estimated position as (lat) dd mm.mm [N/S] (lng) ddd mm.mm [E/W]\n:");
	}
	getsptr = mygets(inbuf,buflen);
	split(inbuf);
	a = x->lat;
	i = llscan(i,&a);
	x->lat = a;
	a = x->lng;
	i = llscan(i,&a);
	x->lng = a;
}

Edit: I think I’ll try something easier in that C program to bridge for a first try.

Yeah, not going to happen. There’s just too much I don’t understand about C, JNI and java. :slightly_frowning_face:

I guess I don’t give up as easily as I thought. I was playing with AS and found myself creating a new C++ project. I took the full C file I have and stuck it into the project. The compiler accepted it. I just need to learn to use JNI.

I guess my question at this point is what can I bridge with JNI? I imagine using java to accept some input and then pass that variable to JNI which translates it, then the C code uses it and the result goes back to JNI to get passed back to java.

Is the C code running throughout all this? It’s all so vague to me.