?
Solved

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

Posted on 2003-03-13
3
Medium Priority
?
180 Views
Last Modified: 2010-04-01

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.

   
 
0
Comment
Question by:cb068
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
EarthQuaker earned 100 total points
ID: 8126832
 FILE * pFile;
  float nFloat;

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

  fclose (pFile);
 
0
 
LVL 1

Expert Comment

by:jadams117
ID: 8126867
Or the C++ version..

std::ifstream inFile("filename.txt");
double number;
inFile >> number;
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9481848
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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question