Re: Reading a file.



On Fri, 27 Jun 2008 11:07:01 -0700, ashishedn
<ashishedn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Problem is when i am reading a file through "readfile" function,it is being
read in character format.

Variation on earlier replies:
ReadFile reads bytes, and reads them exactly as it finds them, with
_no_ translation. How your program interprets those bytes depends on
how it stores them in memory. So if you read the bytes into a char
(ASCII) array, your program will interpret them as ASCII. But if you
read them into an int array, your program will interpret the exact
same bytes as integers.



Suppose a value "9" is read,then it would get stored
in memory as "0x39" and i would be getting "0011 1001" instead of "0000 1001".
so the question is whether with "readfile" function a value could be read in
decimal format?

"Bruce Eitman [eMVP]" wrote:

You may have said something before, just not clear enough for the rest of to
understand what your problem is, and you still haven't done a very good job
of it.

Could it be that you saved the file with something like "%X", data? And so
now you need to convert it?

As I stated before: Then explain better what you expect and what is
actually happening.

--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT EuroTech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

EuroTech Inc.
www.EuroTech.com

"ashishedn" <ashishedn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:50323539-6D7B-45E0-B096-7DAB20E80E65@xxxxxxxxxxxxxxxx
That i have already tried.what is happening,if i fill data to the buffer
as
integers then it is showing correct value.However,if data filled to the
buffer is character values, then in memory ASCII values are displayed.
But,for our main application, in both the cases(defining buffer as set of
integers/characters) ASCII values are coming.Therefore,i can't get correct
bitwise information as told earlier.

"Bruce Eitman [eMVP]" wrote:

Huh?

What is the problem? Reduce this a little, I suspect that it has nothing
to
do with "reading a file".

What happens if you take a array and fill it with hard coded data, then
do
the operation? Doing so might help you understand what is going on, and
certainly would help me understand.

Then explain better what you expect and what is actually happening.

--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT EuroTech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

EuroTech Inc.
www.EuroTech.com

"ashishedn" <ashishedn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C59D4C87-F2BA-405A-AC4A-2FE26532C29D@xxxxxxxxxxxxxxxx
Hi,
I am trying to read data from a file to a buffer.Then, i want to store
bitwise information of a particular byte to a different array.
Problem in doing so is, in memory, ASCII value of a character is
getting
stored and right shifting that value would't give the correct bitwise
information.
Pl. help.

Code written for that is.

#include "stdafx.h"

bool hw[4][8][8];

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
unsigned char inBuffer[256];
unsigned char i,j,k;
DWORD noofbytes = 0x00000001,nBytesRead;
HANDLE hservice = CreateFile(L"\\hi.txt",GENERIC_READ,0,NULL,
OPEN_EXISTING,0,NULL);
DWORD d = GetLastError();
if(hservice != INVALID_HANDLE_VALUE)
{
DWORD dwPtr = SetFilePointer(hservice,0x00,NULL,FILE_CURRENT);
if(dwPtr == 0xFFFFFFFF)
{
printf("Pointer set error = %ul\n",GetLastError());
// return 0;
}
else
{
BOOL bResult =
ReadFile(hservice,&(inBuffer[i]),noofbytes,&nBytesRead,NULL);
DWORD d = GetLastError();
if(bResult && (nBytesRead == 0x01))
printf("Read Value = %x\n",inBuffer[i]);
else
printf("Error in Reading = %ul\n",d);
}
}
else
printf("Error in opening the file = %ul",d);
for(k=0;k<8;k++)
{
// printf("value of in Buffer = %d\n",inBuffer[j]);
if(inBuffer[0]>>k & 0x01)
hw[0][0][k] = TRUE;
else
hw[0][0][k] = FALSE;
printf("Value of hw[0][0][%d] = %d\n",k,hw[0][0][k]);
}
return 0;
}








-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 478
Boston, MA 02116
www.penfact.com
.



Relevant Pages

  • Re: Reading a file.
    ... Problem is when i am reading a file through "readfile" function,it is being ... Bruce.Eitman AT EuroTech DOT com ... buffer is character values, then in memory ASCII values are displayed. ... DWORD d = GetLastError; ...
    (microsoft.public.windowsce.app.development)
  • Re: what does "serialization" mean?
    ... Sorry eddie, but you're dead wrong there as usual. ... >>How about ASCII character 0xB0, ... > Totalitarians and Fascists are often self-appointed language police. ...
    (comp.programming)
  • Re: what does "serialization" mean?
    ... > attempt to present myself as an authority on any and every topic I have ... >> survived and EBCDIC did not because ASCII properly sequenced letters. ... > How about ASCII character 0xB0, ... >> must assert negative facts, for all he knows is there is no knowledge ...
    (comp.programming)
  • Re: Cohens paper on byte order
    ... I think you're using "ASCII" in a notional sense. ... a good reason to teach the *opposite* convention, ... Computers should be as easy to understand as is possible _without_ ... arithmetic on character strings ...
    (sci.crypt)
  • Re: Get ASCII values for PC arrow keys?
    ... those responsible for standards usually do attempt ... ASCII is a character set, ... ISO/IEC registry for character sets for them to receive identifying ...
    (alt.comp.lang.learn.c-cpp)