|
Iain Clarke wrote: Poetry SDK
Wonderful.
Welcome again (and again) in the, well you know which one, list [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
pervise.zhao wrote: Welcome your advice!
My advice: change your career, there're always job opportunities at McDonald's.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
I am using QNX IDE.
I need to create a file which is exactly 2112 bytes.T.he data written to the file must be of type char(in Hexadecimal format.
I am trying following code.
#include "stdio.h"
#include "conio.h"
#include<stdlib.h>
#include<fstream.h>
void main()
{
FILE* fs;
fs=fopen("c:\\RajC\\randomF.txt","w");
srand(255);
for(unsigned char i=0;i<255;i++)
{
printf("%c\t",rand());
fprintf(fs,"%x\t",rand());
}
getch();
}
but the output of the above program gives me a file of 6.08KB,whereas I need just a filesize of 2112bytes.
I need to use this file for testing on a hardware.
*/
Can anyone help me.
Thanks in advance.
Regards,
Purusottam Mishra
Purusottam Mishra
Systems Executive
|
|
|
|
|
Writing a single char takes 1 byte. including '\t' tabs. You are running the loop 255 times. So if you just print 1 char in the loop, the file size becomes 255 bytes. if you print the hex value, it defers based on the number it generates. May be you can format the string to a standard size and calculate the size accordingly. Remember the tab takes 1 byte.
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
If you are able to call Windows APIs, you can use SetFilePointer followed by SetEndOfFile .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I strongly suggest you to revise your requirements.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yes sir.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
[military tone]
Stand easy!
[/military tone]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
This should work:
#include <io.h>
#include <fcntl.h>
void main()
{
int fd=open(file-path,O_RDWR|O_BINARY|O_CREAT|O_TRUNC);
if (fd != -1)
{
const size_t numBytes = 2112;
unsigned char buffer[numBytes]={0};
const int x = write(fd, buffer, numBytes);
close(fd);
}
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks a lot for the reply.
But can u gimme a C++ style solution,i.e. using fstream.
I am trying it this way:
void Create_Page_File()
{
int iCount;
char wbuf[PAGESIZE];
int rand_no;
memset (wbuf, 0, PAGESIZE);
ifstream infile("/tmp/TestData.bin");
ofstream outfile("/tmp/TestData.bin");
for( iCount = 0; iCount < PAGESIZE; iCount++ )
{
rand_no = rand( );
wbuf[ iCount ] = ( rand_no % 0xff );
outfile.write( &( wbuf[ iCount ]), 1 );
cout<< wbuf[iCount]<<" ";
}
}
But the resulting file I am getting is in character format,nd not hexadecimal.
Please Help me.
Thanks and regards,
Purusottam Mishra
Systems Executive
|
|
|
|
|
std::ofstream a("b.b", std::ios::binary|std::ios::trunc);
a << std::string(2112, (char)0);
<div class="ForumSig">Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p</div>
|
|
|
|
|
This is not working.
Can you please make it in detail.
Actually I am just a newbie.
Thanks for the reply.
Purusottam Mishra
Systems Executive
|
|
|
|
|
Raj-Ekoham DwitiyoNasti wrote: This is not working
It creates a file called b.b in the current directory which is exactly 2112 bytes in length. Want a different filename? Then change it in the constructor. Want a different file length? Then change the length (2112 in this case) in the string constructor
Otherwise, what do you mean by 'not working'?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I mean that the file b.b has its contents as "char" and not Hexadecimal.
The previous example that u'd given me(C Style), the fwrite() converts the char data to Hexadecimal implicitly.
for(iCount=0; iCount<PAGESIZE; iCount++)
{
rand_no = rand();
wbuf[iCount] = (rand_no % 0xff);
fwrite(&(wbuf[iCount]),sizeof(char),1,fp);}
Is there any way to do so using C++.
Thanks and Regards,
Purusottam Mishra
Systems Executive
|
|
|
|
|
Raj-Ekoham DwitiyoNasti wrote: I mean that the file b.b has its contents as "char" and not Hexadecimal.
There's no difference between 'char' and 'hexadecimal' - they're all just numbers. The only difference with char is that the numbers are understood to map onto characters.
Try this - and look at the file contents after it's run - they're as random as you want.
std::ofstream a("b.b", std::ios::binary|std::ios::trunc);
std::generate_n(std::ostream_iterator<char>(a), 2112, rand);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have created a Dialog-based MFC project,and I want to put a CPropertySheet on the Dialog,as it does in the case of normal controls which are children of Dialog.
In the PropertySheet,I have pages which are CDialogShelf(class CDialogShelf : public CPropertyPage),and in each page there lies some CButtons.My goal is to deal with the action when user hit button.
In CDialogShelf :
<br />
BEGIN_MESSAGE_MAP(CDialogShelf, CPropertyPage) <br />
ON_CONTROL_RANGE(BN_CLICKED,BTNID_0,BTNID_0+BTN_NUM,OnBnClikedBtn) <br />
END_MESSAGE_MAP() <br />
<br />
void CDialogShelf::OnBnClikedBtn(UINT uID) <br />
{ <br />
UINT BtnID = uID - BTNID_0; <br />
CString tmpStr; <br />
<br />
tmpStr.Format(_T("it is: %d"),BtnID); <br />
AfxMessageBox(tmpStr); <br />
} <br />
When user hit one of the button,the function is called indeed.But if I put a break point in debugging,the program dies,it can't respond any more.There must be some problems.
What I have tried is somthing with the creation of PropertySheet:
m_PropSheet.Create(this,WS_CHILD, 0);
if I replace WS_CHILD with WS_POPUP,everything goes OK.But this makes the PropertySheet indepent from Dialog.
How to fix that?
|
|
|
|
|
You should use the Tab control instead of CPropertySheet.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I have no idea about their differences.Expecting more explanation.
|
|
|
|
|
A property sheet is a dialog on its own.
Since you already have a dialog, you can use the tab control and then place controls into the tab control.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
OK,I'm beginning to understand.One of my colleague once used tab control instead of property sheet.I know the reason now.Thanks superman!
|
|
|
|
|
You can also remove the main dialog and let the propertysheet act in its place.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I think it's better use tabctrl,I'll have a try.
|
|
|
|
|
I want to use the MATLAB compiler to build a C++ programe
and I use a demo to try the compilation
However, there are error when I using the command
************************************************************************
mcc -W cpplib:libmyadd -T link:lib myadd.m
************************************************************************
The error msg is:
************************************************************************
Compiler version: 4.8 (R2008a)
Processing G:\MATLAB\R2008a\toolbox\matlab\mcc.enc
Processing include files...
2 item(s) added.
Processing directories installed with MCR...
The file mccExcludedFiles.log contains a list of functions excluded from the CTF archive.
1 item(s) added.
Generating MATLAB path for the compiled application...
Created 38 path items.
Begin validation of MEX files: Wed Mar 11 04:09:51 2009
Validating 'G:\MATLAB\R2008a\toolbox\compiler\deploy\deploywhich.mexw32'.
No conflicting M-file found.
Validating 'G:\MATLAB\R2008a\toolbox\compiler\deploy\readline.mexw32'.
No conflicting M-file found.
End validation of MEX files: Wed Mar 11 04:09:51 2009
Deleting 2 temporary MEX authorization files.
Removing: 'C:\DOCUME~1\DESERT~1\LOCALS~1\Temp\mathworks_tmp_4652_4530_4652.auth'.
Removing: 'C:\DOCUME~1\DESERT~1\LOCALS~1\Temp\mathworks_tmp_4652_7210_4652.auth'.
Parsing file "G:\FYP\M-file\myadd.m"
(Referenced from: "Compiler Command Line").
Parsing file "G:\MATLAB\R2008a\toolbox\compiler\deploy\deployprint.m"
(Referenced from: "Compiler Command Line").
Parsing file "G:\MATLAB\R2008a\toolbox\compiler\deploy\printdlg.m"
(Referenced from: "Compiler Command Line").
Generating file "libmyadd.h".
Generating file "libmyadd.cpp".
Generating file "libmyadd.exports".
Generating file "G:\FYP\M-file\readme.txt".
Generating file "libmyadd_mcc_component_data.c".
Executing command: mbuild -O -v -output "libmyadd" "libmyadd.cpp" "libmyadd.exports" "libmyadd_mcc_component_data.c" -link shared
This is mbuild Copyright 1984-2004 The MathWorks, Inc.
-> Default options filename found in C:\Documents and Settings\Deserterize\Application Data\MathWorks\MATLAB\R14
----------------------------------------------------------------
-> Options file = C:\Documents and Settings\Deserterize\Application Data\MathWorks\MATLAB\R14\compopts.bat
-> COMPILER = cl
-> Compiler flags:
COMPFLAGS = -c -Zp8 -G5 -GX -W3 -nologo -DMSVC -DIBMPC -DMSWIND
OPTIMFLAGS = -O2 -DNDEBUG
DEBUGFLAGS = -Zi -Fd"libmyadd.pdb"
arguments =
Name switch = /Fo
-> Pre-linking commands =
-> LINKER = link
-> Link directives:
LINKFLAGS = kernel32.lib user32.lib gdi32.lib advapi32.lib oleaut32.lib ole32.lib /LIBPATH:"G:\MATLAB7\\extern\lib\win32\microsoft\msvc60" /nologo mclmcrrt.lib /dll /implib:"libmyadd.lib" /def:_lib1143.def
LINKFLAGSPOST =
Name directive = "/out:libmyadd.dll"
File link directive =
Lib. link directive =
Rsp file indicator = @
-> Resource Compiler = rc /fo ".res"
-> Resource Linker =
----------------------------------------------------------------
--> "cl -c -Zp8 -G5 -GX -W3 -nologo -DMSVC -DIBMPC -DMSWIND /Folibmyadd.obj -IG:\MATLAB7\\extern\include -IG:\MATLAB7\\simulink\include -O2 -DNDEBUG libmyadd.cpp"
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
cl : Command line warning D9002 : ignoring unknown option '-G5'
libmyadd.cpp
libmyadd.cpp(8) : fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
G:\MATLAB7\\BIN\WIN32\MEX.PL: Error: Compile of 'libmyadd.cpp' failed.
Error: An error occurred while shelling out to mbuild (error code = 255).
Unable to build executable.
??? Error using ==> mcc
Error executing mcc, return status = 1.
************************************************************************
and my M-file is:
************************************************************************
function [y,z] = myadd(a, b)
% dummy function, just to demonstrate the idea
y = a+b;
z = a+2*b;
end
*************************************************************************
So, what is the problem when I using the mcc function?
and What should I do to solve this problem??Thanks
|
|
|
|
|
deserterize wrote: libmyadd.cpp(8) : fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
that should give you a clue
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|