Click here to Skip to main content
14,117,047 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
hi everyone!
 
I would like to know how you can put a matrix that came from c + + code in the Java console in an matrix in java. In fact, I send parameter to my c + + code from the java code, and the receipt of income is at the java console in the form of a text. so, I want to extract the matrix from the text .I need later in the code, I honestly do not know how.
 
below, this is my java code
OutputStream out = null;
     OutputStream err = null;
     PipedInputStream pipedInput = new PipedInputStream();
     PipedOutputStream pipedOutput = new PipedOutputStream(pipedInput);
     Program prog = new Program("C:\\Users\\abdelhalim\\Desktop\\ExempleMMKP33.exe", System.out, System.err, pipedInput);
        // TODO: Write pipedOutput from your favorite thread to send input to the program and finally close the stream.
        // I will use a PrintWriter because we are working here with text and not binary data.
        PrintWriter pw = new PrintWriter(pipedOutput);
        // println outputs platform specific newline but pw.print("5\n" ) would also convert "\n" to platform specific newline.
      
      
       res1= new int[n][m];
        pw.println(m);
        pw.println(n);
        pw.println(m);
        pw.println(n);
      
        for(int k=0; k<R.size();k++)
        { 
        pw.println(R.get(k));
        }
      
        for(int k=0; k<C.size();k++)
        {
       
        pw.println(C.get(k));
        }
        for(int k=0; k<B.size();k++)
        {
       
        pw.println(B.get(k));
        }
        for(int k=0; k<Dr.size();k++)
        {
       
        pw.println(Dr.get(k));
        }
        for(int k=0; k<Dc.size();k++)
        {
       
        pw.println(Dc.get(k));
        }
        for(int k=0; k<Db.size();k++)
        {
       
        pw.println(Db.get(k));
        }
        /*for(int k=0; k<n;k++)
        {
      for(int j=0; j<m;j++)
 	    pw.println(GainMatrix[k][j]);
 	   }*/
        pw.println(n);
        pw.println(m);
        pw.println(m);
        pw.println(m);
pw.close();


and this is what I get in the java console:

0   0   0   0   1   0
   0   0   0   0   0   1
   0   1   0   0   0   0
   0   0   0   1   0   0
   0   0   0   0   1   0
   0   0   1   0   0   0
Initial
propagators: 24
branchers:   1
Summary
runtime:      1.735 (1735.000 ms)
solutions:    48
propagations: 1715
nodes:        153
failures:     29
restarts:     0
peak depth:   7
peak memory:  13 KB


I want to put this matrix in a java code matrix (matrix type res1 = new int [n] [m]) after the reception and I do not know how to do it ??,,
 
you have an idea about that?? thank you very much for your help
Posted
Comments
Richard MacCutchan 1-Nov-13 14:22pm
   
Read the text data and convert each field to integer and store in the matrix.
Manel1989 1-Nov-13 16:42pm
   
thank you very much

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Read the console output as string and scan it. A space means end of integer, a new line a new row. You scans the string twice: first run to detect the dimensions and second run to read the values.

Very important: Implement robust error handling!!!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190518.1 | Last Updated 5 Nov 2013
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100