4 Replies Latest reply: Nov 13, 2007 11:57 AM by 807603 RSS

    How i can convert a line program into string...?

    807603
      Hi,

      I need recode a C program to java but i've a problem with ones sentence, in C i can do this

      #define Asign(a,b,c) debug_asign(a,#b,#c, b,c);

      void debug_asign(char* a, char* bStr, char*cStr,int b, double c)
      {
      char line_debug[513];
      sprintf(line_debug, "%s - Val[%s] = %lf [%s]", a,bStr,c,cStr);
      .....
      vals[ b ]=c;
      }
      --------------

      this generate a string line_debug with
      (Example)
      "12 - Val[123] = 0,0204 [  (12+5) *  0.012 ]";

      This is a reduce code about this functions type.

      My problem is, how i can do this in java????, generate a string line with the string expresions evaluates for a calcule???

      Any have idea? please

      thx
        • 1. Re: How i can convert a line program into string...?
          807603
          What part are you asking about? The macro or the way that you're using a char array variable oddly (and IIRC mistakenly)?

          Are you aware that you're not actually evaluating the string?
          • 2. Re: How i can convert a line program into string...?
            masijade
            Don't try to convert a C program line for line to a Java program. They are completely different. C is procedural, Java is Object Oriented. The two don't mesh. They are not one-to-one translatable. Figure out what the C program is meant to do, and reprogram it in Java. You can use parts of the C program as a template for some tricky areas, maybe, sometines, but you cannot just simply translate one to the other. It doesn't work that way. Technically you can, but expect the "new" Java version of the C program to have about half the efficiency, in that case, which pretty much negates the purpose of the rewrite.
            • 3. Re: How i can convert a line program into string...?
              807603
              I need simulate the macros behavior (#), in small words...take a code of calculate and write in a log one by one the execution and evaluate intructions and variables. Example.

              this C program use a very long calculate formules, and is prioritary check the calcule and write al the steps, that C macros can do. That write all the steps and variable values used.

              Example

              if(x==(beta*alfa / sin(y))) then bla bla bla...

              write in log:

              Si ( X == (BETA * ALFA / SIN(Y))))
              with
              X = 2.15; BETA=1; ALFA=0.1; Y=4;

              i need a similar logs...not equal to C may be using objects, etc..
              But in java i not know how i can write a operator ... In C++ i know
              only use

              CClass::operator == (double value)
              {
              ...
              }

              but in java??
              • 4. Re: How i can convert a line program into string...?
                807603
                Thats rigth, i only need simulate in java this log type, the log using macros allow me register all calcule with the variable values, is a scientific program :S, is prioritary register al calculate.


                One idea may by generate a interpreter language how to Basic, and migrate this calculate routines to Basic, but is too large process to implement in my short develop time.

                That is why i question to yours if any know a simply form to do that, similar to macros uses or have another idea

                thx