CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2009
    Posts
    1

    Exclamation conversion from c to java

    Hi,
    I'm working in conversion of code from c to java, what will be the equivelent for the following code.


    typedef struct bit_file {
    FILE *file;
    unsigned char mask;
    int rack;
    int pacifier_counter;
    } BIT_FILE;

    void OutputCode( output_file, code )
    BIT_FILE *output_file;
    int code;
    {
    int top_of_range;
    int abs_code;
    int bit_count;

    if ( code == 0 ) {
    OutputRunLength++;
    return;
    }
    if ( OutputRunLength != 0 ) {
    while ( OutputRunLength > 0 ) {
    OutputBits( output_file, 0L, 2 );
    if ( OutputRunLength <= 16 ) {
    OutputBits( output_file,
    (unsigned long) ( OutputRunLength - 1 ), 4 );
    OutputRunLength = 0;
    } else {
    OutputBits( output_file, 15L, 4 );
    OutputRunLength -= 16;
    }
    }
    }
    if ( code < 0 )
    abs_code = -code;
    else
    abs_code = code;
    top_of_range = 1;
    bit_count = 1;
    while ( abs_code > top_of_range ) {
    bit_count++;
    top_of_range = ( ( top_of_range + 1 ) * 2 ) - 1;
    }
    if ( bit_count < 3 )
    OutputBits( output_file, (unsigned long) ( bit_count + 1 ), 3 );
    else
    OutputBits( output_file, (unsigned long) ( bit_count + 5 ), 4 );
    if ( code > 0 )
    OutputBits( output_file, (unsigned long) code, bit_count );
    else
    OutputBits( output_file, (unsigned long) ( code + top_of_range ),
    bit_count );
    }
    void OutputBits( bit_file, code, count )
    BIT_FILE *bit_file;
    unsigned long code;
    int count;
    {
    unsigned long mask;
    mask = 1L << ( count - 1 );
    while ( mask != 0) {
    if ( mask & code )
    bit_file->rack |= bit_file->mask;
    bit_file->mask >>= 1;
    if ( bit_file->mask == 0 ) {
    if ( putc( bit_file->rack, bit_file->file ) != bit_file->rack )
    printf( "Fatal error in OutputBit!\n" );
    else if ( ( bit_file->pacifier_counter++ & PACIFIER_COUNT ) == 0 )
    putc( '.', stdout );
    bit_file->rack = 0;
    bit_file->mask = 0x80;
    }
    mask >>= 1;
    }
    }

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: conversion from c to java

    r_punidha, I don't believe there is a free C-to-Java translation service here.

    If you show us what you've got so far, and what you're stuck on, we may be able to help you with it.

    Reinventing the wheel is a process...
    R. Elisha
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Aug 2005
    Posts
    198

    Re: conversion from c to java

    That's not valid C code.

    e.g., the following makes no sense at all - since when can you define variables between the method header and the opening brace of the method?
    [code]
    void OutputCode( output_file, code )
    BIT_FILE *output_file;
    int code;
    {
    ...
    [/code/

    Where did you get this C code?
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  4. #4
    Join Date
    May 2009
    Location
    Lincs, UK
    Posts
    298

    Re: conversion from c to java

    Quote Originally Posted by David Anton View Post
    since when can you define variables between the method header and the opening brace of the method?
    Since C was designed (around 1972). That is actually the declaration of the formal parameters passed to the method, not the definition of variables. I could agree with you that it is a bit old fashion, but it is still perfectly valid.

  5. #5
    Join Date
    Aug 2005
    Posts
    198

    Re: conversion from c to java

    Which compilers allow it?
    I do most of my testing in VC++ and it doesn't compile there.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  6. #6
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: conversion from c to java

    Borland C =))))
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

  7. #7
    Join Date
    May 2009
    Posts
    2,413

    Re: conversion from c to java

    Quote Originally Posted by r_punidha View Post
    Hi,
    I'm working in conversion of code from c to java, what will be the equivelent for the following code.
    Just an idea of a different approach. Java has an interface called JNI. It allows you to call code written in other languages, like C, from Java.

    In your case it may be easier to collect a library of C code, and then use it from Java via JNI.

    Say you have millions of lines of C code. Instead of turning them into Java you make a C library out of them and call them from Java instead.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured