Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting arrays/pointers from C to Java

I am trying to re-write a program in C to java. I have no experience in C, but some in C++, so I understand some of the pointer/array things. I am slightly confused though...I am given the following code in C:

void ProcessStatus(Char *Stat){
    DWORD relayDate;
    DWORD APIDate;

    version3=false;
    version4=false;
    version9=false;
    tiltAngle = false;
    ver4features=0;
    tooNew=false;
    ProgRev=0;

    switch(Stat[14]){

From what I understand, the function ProcessStatus is passed a pointer to a char; and I'm assuming since in the last line of the code provided Stat[14] is called its within in array.

So what I'm confused about is how I would pass a pointer to a char within an array in Java.

Any help would be appreciated, even if its helping with my understanding of the C code. Thanks.

like image 250
JuiCe Avatar asked Dec 26 '22 21:12

JuiCe


1 Answers

Hard to say whether it's a string or a raw data that has been passed.

In case of string, use Java's built-in String class.

void ProcessStatus( String stat)
{
  ...

  switch ( stat.charAt( 14 ) )
  {
  } 
}

In case of raw data array, use byte array

void ProcessStatus( byte[] stat)
{
  ...

  switch ( stat[ 14 ] )
  {
  } 
}

BTW, C's char data type is translated to byte type in Java. char type in Java denotes a UTF-16 character which is 2 bytes long. byte is exactly what it is (8-bits, signed).

like image 67
Alexander Pogrebnyak Avatar answered Jan 06 '23 23:01

Alexander Pogrebnyak