Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7684701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:05:19+00:00 2026-05-31T19:05:19+00:00

The C code i need to convert into Java is: typedef struct { short

  • 0

The C code i need to convert into Java is:

typedef struct
{
    short ih;
    ....
} lsettings;

int ldc_read_parameters(char *param_fnm, lsettings settings, short *image_height)
{
   FILE *fp_param;
   char line[256];
   fp_param = fopen(param_fnm, "r");

   if (fp_param) 
   {
      do fgets(line, 256, fp_param); 
         while (line[0] == '#');

      sscanf(line, "%hd", &settings.ih);
      *image_height = settings.ih;
   }
}

The Java code i have written is:

class lsettings
{
  public short ih;
  .....
}

int ldc_read_parameters(String param_fnm, lsettings settings, short image_height[])
{
    Scanner fp_param;        
    String line;
    fp_param = new Scanner(new BufferedReader(new FileReader(param_fnm)));
    if (fp_param.hasNext())
    {

        do
        {
            line=fp_param.nextLine();

        } while (line.charAt(0) == '#');
        Scanner s=new Scanner(line);
        settings.ih=s.nextShort();
        image_height[0] = settings.ih;
     }
}

Have i done the conversion correctly or something is wrong here. I am not sure about the sscanf function. Please help. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:05:21+00:00Added an answer on May 31, 2026 at 7:05 pm

    man sscanf

    The scanf() function reads input from the standard input stream stdin, fscanf() reads input from the stream pointer stream, and
    sscanf() reads its input from the character string pointed to by str.

    h Indicates that the conversion will be one of d, i, o, u, x, X, or n and the next pointer is a pointer to a short int or
    unsigned short int (rather than int).

    http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html#nextShort()

    Both sscanf and nextShort converts next value to short (in c version you have unsigned short). If you want to have the same precision – change short to int. short in java in always signed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert 2 bytes (2's complement) into an int in Java code.
I need to convert a python code into an equivalent java code. Python makes
I need to create a porting software that will convert Java code to C#
I have a function in Java which I need to convert into php. It
I need to convert C code to Java. The minimal C code is: void
I am trying to convert the code snippet given in this http://www.movable-type.co.uk/scripts/latlong.html into java.
I need to convert a variable from JavaScript into a Java variable. I'm asking
I am trying to convert Java code into Objective C code. And the java
I need to convert string into ASCII code. I'm using python. I did as
I have one function in oracle i need to convert it into c# code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.