need help converting this c code to java (short)

Associate
Joined
21 May 2003
Posts
1,008
Hi. I need to work out how to write the following in java:
Code:
struct times {
    int time ;
    char c ;
  } input_data[ NINPUT_DATA ] ;

so far I have:
Code:
public class times{
		int time;
		char c;
	} ;
	public times[] input_data  = new times[NINPUT_DATA];

but when i try and access something (i.e t.input_data.time), i get an error NullPointerException.

anyone have any ideas?
 
ok, that has sorted a lot out, but i really don't like the for look that initialises all the data. say if i want to initialise them all to 0, can i do :

Code:
//constructor
	public times() {
		this.time =0 ;
		this.c = 0;
	}

so that way at the beginning when it makes them all, it puts 0 in all of them?

or should i change it to:
Code:
private int time = 0;
	private char c = 0;
 
Back
Top Bottom