Accessing a double number in a file from C (the double is written to file from Java with writeDouble method)


I have a java program that uses the writeDouble() method of RandomAccessFile class and writes a double number to an o/p file. Now, I want to access that file from C side and retrieve the double number. How do I do it? (fscanf,fread etc donot seem to work).

This is the Java code

import java.io.*;
class gendouble{
    public static void main(String args[])
    {
     try
         {
          File gen=new File("\\gen");
          RandomAccessFile filehandle=new RandomAccessFile(gen,"rw");
                filehandle.writeDouble(102.123);
         }
     catch(FileNotFoundException ex){}
     catch(IOException ex){}
    }
}

Now, how do I retrieve the value 102.123 that has been written to the o/p file named gen from C side?

Thank you.

   
 
cb068Asked:
Who is Participating?
 
EarthQuakerConnect With a Mentor Commented:
 FILE * pFile;
  float nFloat;

  pFile = fopen ( "myfile.txt" , "rb" );
  if (pFile==NULL) exit (1);
 
  fscanf(pFile, "%f", &nFloat);

  fclose (pFile);
 
0
 
jadams117Commented:
Or the C++ version..

std::ifstream inFile("filename.txt");
double number;
inFile >> number;
0
 
tinchosCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: EarthQuaker

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.