473,609 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with fstream::read

21 New Member
I'm having a problem with read , my code is somewhat like:
Expand|Select|Wrap|Line Numbers
  1. char chipMemory [chipMemorySize]; // ~35XX
  2. fstream ifile;
  3. ifile.open(argv[1],ios::in|ios::binary|ios::nocreate|ios::ate);
  4. int fileLength=ifile.tellg();
  5. ifile.seekg(ios::beg);
  6. ifile.read(chipMemory,fileLength);
  7. ifile.close();
After the last function call in the program, (Note , this is an extract , and seemingly irrelevant pieces have been removed)
(short) chipMemory[0] "prints as" (printf used) 0xFFFFFFE0
(short chipMemory[2] "prints as" 0xFFFFFFEE
it should contain:
(short) chipMemory[0] == 0x00E0;
(short) chipMemory[2] == 0x00EE;
What I'm most puzzled about is that a short is 2 bytes , so the maximum short would be 0xFFFF , not even close to 0xFFFFFFE0.
I'm guessing this is because the file starts with a nul (0x00) , which is supposed
to mark the end of a file.
(Note : I'm not checking for nul in any way at all)
Jul 19 '08 #1
1 1833
jabbah
63 New Member
Im not prefectly sure but could it be that 0x00E0 overflows char? should you be using unsigned char?


Expand|Select|Wrap|Line Numbers
  1. printf("%d\n", 0x00E0 );
  2. char c = 0x00E0;
  3. printf("%d\n", c);
  4. printf("0x%x\n", c);
  5. printf("0x%x\n", (short)c);
  6.  
Jul 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

20
2661
by: titi | last post by:
Question The road and traffic authority for a small country currently uses a system to store information about all 'currently' licensed drivers. A licensed driver has the following info stored about them in a record; 1. Given name(s) of the license holder.(not more than 128 char (may have spaces)). 2. Surname of the license holder.(Not more then 128 same like above).
2
6080
by: dumboo | last post by:
hi there i m using fstream object for reading through and writing to my file, using following code char c; while(!m_aa.eof()) { m_aa.read(&c, sizeof(c)); m_oo.write(&c, sizeof(c));
1
1642
by: Patrick | last post by:
Hi I try to parse an XML Document with the following commands: response = http.responseXML.documentElement; up_since =response.getElementsByTagName('up_since').firstChild.data; So I try to read out the value for up since, but then I get the error message
5
1958
by: Scott Shuster | last post by:
Hi, I'm having some strange problems in VS employing a DataReader. Here's a small snippet of the code: .... objDR = objCMD.ExecuteReader() If objDR.Read() Then (true stuff) Else
5
1385
by: Simon Verona | last post by:
I have a pair of functions that I'm calling using remoting - called readfile and writefile. The readfile works fine when called from the client PC. The writefile method returns an error: "Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed".
5
2045
by: znubbe | last post by:
Hi, I hope anyone can help me with this problem. I have a field of image type in a SQL 2000 database. I'm using this code to insert a document: Dim conn Dim rs Dim oStream
10
3592
by: Hunk | last post by:
Hi I would like some ideas on way to solve the concurrency issue. The problem is , I have an object say X which multiple readers need to access and also to update. They do so by say two functions : // simplistic view of the problem Read() { return X; }
7
1938
by: nma | last post by:
Hi I'm trying to display data in a table list format but error message like this appear. What is wrong with the code? "Parse error: syntax error, unexpected '<' in C:\htdocs\...\MB2movieinfo.php on line 27" I'm trying to display data from table in databse in new window and there is a close window button to close the opened window. TQ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
8
33154
by: No Signal X | last post by:
hello i'm having a problem in reading a text file line by line with splitting words, counting the number of lines & words and saving the position of each word i've started with this : public void readlineandword() throws IOException{ BufferedReader rd = new BufferedReader(new FileReader("t1.txt")); String line = rd.readLine();
0
8121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8062
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
6987
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5506
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4010
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4068
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1378
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.