|
Hello
I am working with binary files in c++. What i am doing is that i am reading at every 5th position in a binary file. if there is 0 then break the loop.
I wrote the following code
what is error in it. I wrote 1 at the start of the file. But it is not showing that 1
Code is
int i = 0;
int count = 0;
ifstream fin("data.bin", ios::in | ios::binary);
while (count != 5120)
{
fin.seekg(count);
cout <<i<<' ';
="" fin.read((reinterpret_cast="" <="" char="" *="">&i, sizeof(i));
if (i == 0)
break;
count+=5;
}
Please reply...
Thanks>
Aqueel A. Mirza
We Believe in Excellence
-- modified at 1:26 Tuesday 1st November, 2005
|
|
|
|
|
Hello.
You are reading sizeof(i) no of charaters from the file. Is that what you want?
i is an integer, so sizeof(i) will evaluate to 4 (bytes).
My guess is that you really want to read one character at the time from the file and then interpret it as an integer, right?
The read it as an unsigned char, with sizeof(unsigned char)
Then, cast it to ant int.
|
|
|
|
|
How do I create a folder in the Program Files directory programatically? I haven't programmed in Win32 the last few years and don't have my win code to refresh my memory. I know it is some COM object function that gets the special location like Trash, Program Files, History..
Thanks in advance.
|
|
|
|
|
LPITEMIDLIST pid;<br />
HRESULT hr;<br />
hr = SHGetSpecialFolderLocation(m_hWnd,0x0026,&pid);<br />
<br />
TCHAR path[MAX_PATH];<br />
SHGetPathFromIDList(pid,path);<br />
<br />
LPMALLOC mal;<br />
SHGetMalloc(&mal);<br />
mal->Free(pid);
I hope it works, and is without errors.
this is this.
|
|
|
|
|
I have used the MFC application wizard in Visual C 6.0 to create a FormView application. The resultant FormView contain the word "Untitled" before the program name I supplied. What is an acceptable method of eliminating the word "Untitled"?
|
|
|
|
|
I believe SetWindowText on the main window is what you need.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
Put the following code in CMainFrame::PreCreateWindow
cs.style &= ~FWS_ADDTOTITLE ;
--
======
Arman
|
|
|
|
|
I'm trying to convert some hexadecimal values into japanese text and I can't figure how to do it. I know I have to use a char set that have the japanese chars like unicode and that japanese is multibytes, but i can't seem to find enough information about how i'm supposed to do it.
It would be awesome if someone could help me whit that.
|
|
|
|
|
U gotta use WideCharToMultiByte and MultiByteToWideChar.
If u tell me the exact format of the input I'll be able to tell u the exact process of decoding.
|
|
|
|
|
I'm reading from a binary file each hexadecimal byte that i put into an integer, and i was converting them into a wchar, and trying to put 2 byte together, but that didn't really work. And finally i was displaying them into a textbox. And I also want to do the reverse process.
|
|
|
|
|
Lets make a little test - u create a little file from what u got, save with the extension .txt, drop it into IE and play with the encoding - try unicode/japaneesse/...
If u can't make it show something u probably did something wrong in decoding the file.
|
|
|
|
|
I managed to display japanese chars, but it's not the good char that is displayed.
could you help me on how to start from 2 separated bit of hexadecimal and put them together correctly to display the good japanese char.
|
|
|
|
|
Hi
I have written some MFC Code - But its not working on all machines !!!
<br />
...<br />
#include "device.h"<br />
#include "receiver.h"<br />
...<br />
#include "MyAppView.h"<br />
<br />
<br />
....<br />
<br />
class CDEVICE<br />
{<br />
public:<br />
...<br />
virtual void doA()=0;<br />
virtual void doB()=0;<br />
virtual void doC()=0;<br />
...<br />
}<br />
<br />
class CRECEIVER : public CDEVICE<br />
{<br />
public:<br />
...<br />
virtual void doA();<br />
virtual void doB();<br />
virtual void doC();<br />
...<br />
}<br />
On some XP machines I retrieve an error after returning from doA()
I debuged with DRWatson
<br />
6036719d 33c9 xor ecx,ecx<br />
6036719f eb03 jmp MyApp+0x771a4 (603671a4)<br />
FEHLER ->603671a1 8b4e1c mov ecx,[esi+0x1c] ds:0023:3034324c=????????<br />
603671a4 ff742410 push dword ptr [esp+0x10]<br />
603671a8 50 push eax<br />
And the Corresponding MAP file delivered
<br />
0001:000760ea ?ActivateTopParent@CWnd@@QAEXXZ 603670ea f nafxcw:wincore.obj<br />
<big> 0001:00076127 ?GetTopLevelFrame@CWnd@@QBEPAVCFrameWnd@@XZ 60367127 f nafxcw:wincore.obj</big><br />
0001:00076168 ?GetSafeOwner@CWnd@@SGPAV1@PAV1@PAPAUHWND__@@@Z 60367168 f nafxcw:wincore.obj<br />
0001:00076186 ?MessageBoxA@CWnd@@QAEHPBD0I@Z 60367186 f nafxcw:wincore.obj<br />
So there should be an error in or at
GetTopLevelFrame
can this be true ??
And/OR how to determin the exact error position ??
Any Idear might help Please !!
THX Tim
|
|
|
|
|
I meant error at
<br />
ActivateTopParent<br />
....
Tim
|
|
|
|
|
I'm going to totally wing it and guess that you are calling an instance of CDevice before the main window is actually done being created. The solution is to have the OnCreate message initialize communication with CDevice.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi
No ... Sorry ...
CDEVICE is initialised in the myAppView Constructor, but the work starts after clicking a menu buttom
for example:
<br />
void startWork()<br />
{<br />
doA();<br />
doB();<br />
doC();<br />
}<br />
or
<br />
void startWork()<br />
{<br />
doB();<br />
doA();<br />
doC();<br />
}<br />
I tried all combinations the error allways comes at returning from doA() ??!??!!
Any suggestions ?
Tim
|
|
|
|
|
FILE *Ofile;
<br />
int fCnt = 0;<br />
sprintf(gz_op_fname,"TargetStatistics%d.txt",fCnt);<br />
while ((Ofile = fopen(gz_op_fname, "r")) != NULL)<br />
{<br />
sprintf(gz_op_fname,"TargetStatistics%d.txt",++fCnt);<br />
fclose(Ofile);<br />
}<br />
I have the above code to create a file TargetStatistics%d.txt.
ie. if TargetStatistics0.txt, TargetStatistics1.txt already exists, then TargetStatistics2.txt will be created.
But sometimes with this code I get Invalid handle exception in the while loop.
and I occurs often when there are more files, say it has to create TargetStatistics20.txt.
Whats the problem here. Thanks in advance.
|
|
|
|
|
Which line do you suppose is going to create the file within yor piece of code?
SkyWalker
|
|
|
|
|
oops..sorry I didnt include the part of code that creates the file.
But the exception is surely occuring in the while loop that I had shown in my previous post, for i checked with outputdebug messages. I also included a debug message inside the while loop, and every time its happening after TargetStatistics5.txt or TargetStatistics6.txt.
Thanks.
|
|
|
|
|
Could you provide the loop as it is? More chances for real help
SkyWalker
|
|
|
|
|
... and also, how is gz_op_fname declared?
SkyWalker
|
|
|
|
|
<br />
char gz_op_fname[100];
...<br />
OutputDebug("Data Acq\n");<br />
<br />
sprintf(gz_op_fname,"TargetStatistics%d.txt",fCnt);<br />
while ((Ofile = fopen(gz_op_fname, "r")) != NULL)<br />
{<br />
OutputDebug(gz_op_fname);<br />
sprintf(gz_op_fname,"TargetStatistics%d.txt",++fCnt);<br />
fclose(Ofile);<br />
}<br />
<br />
OutputDebug("Search Op file \n");<br />
these are the debug messages...
TOUCHCORDTOOL : Data Acq
TOUCHCORDTOOL : TargetStatistics0.txt
TOUCHCORDTOOL : TargetStatistics1.txt
TOUCHCORDTOOL : TargetStatistics2.txt
TOUCHCORDTOOL : TargetStatistics3.txt
TOUCHCORDTOOL : TargetStatistics4.txt
TOUCHCORDTOOL : TargetStatistics5.txt
TOUCHCORDTOOL : TargetStatistics6.txt
TOUCHCORDTOOL : TargetStatistics7.txtFirst-chance exception at 0x77f91c3c in EloTouchCordTool-Circle.exe: 0xC0000008: An invalid HANDLE was specified.
Unhandled exception at 0x77f91c3c in EloTouchCordTool-Circle.exe: 0xC0000008: An invalid HANDLE was specified.
|
|
|
|
|
Manu_81 wrote: But sometimes with this code I get Invalid handle exception in the while loop.
and I occurs often when there are more files, say it has to create TargetStatistics20.txt.
Have you tried single-stepping through the code and noting the value of gz_op_fname when the exception is thrown? Is the variable large enough (e.g., MAX_PATH ).
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
If I do single stepping this exception does'nt occur.
|
|
|
|
|
Does the following help:
FILE *pFile;
char szFilename[MAX_PATH];
int nCount = -1;
do
{
nCount++;
sprintf(szFilename, "TargetStatistics%d.txt", nCount);
} while (_access(szFilename, 0) == 0);
pFile = fopen(szFilename, "r");
...
fclose(pFile);
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|