Current location: Hot Scripts Forums » Programming Languages » Everything Java » Porting java to C++!

Porting java to C++!

Reply
  #1  
Old 09-06-04, 02:03 PM
addit addit is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Porting code from java to C++!

Hello all, I've stumbled across a slight problem while trying to port some java code to c++. The following java code is:
Code:
...
DataInputStream dis = null;
try {
dis = new DataInputStream (new BufferedInputStream(new FileInputStream("fileblah"))); // create the stream
}
...
try {
int number = dis.readInt();
}
....
Now all the above is doing is reading an interger from the file right? In other words four bytes from a file. So this is the my code in C++: (i'm using stdio, yes yes yes i know, i know?!)
Code:
...
int number;
fread ((char *) &number,4,1,file);
...
However the java code returns: 435
Where as my c++ code returns: -1291780096

Whats going on? I'm still quite a new at all this. Can anyone try and help me port that java code to c++ so it returns the same number! (you don't have to use the standard library).

Thanking you in anticipation,
Adam

P.S. I posted this in the C++ forum already, just thought you guys might have a better chance of helping me with this

Last edited by addit; 09-06-04 at 02:35 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Porting from java to c++! addit C/C++ 3 09-14-04 05:11 PM
java based lan process monitoring fahad1 Everything Java 1 08-15-04 05:41 AM
We need more java talk rooshine Everything Java 4 05-08-04 11:44 PM
urgent help-voice chat in java ssblessing Everything Java 1 04-02-04 01:02 PM
java tables bwge JavaScript 1 03-09-04 06:50 AM


All times are GMT -5. The time now is 12:28 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)