|
siddharthsan wrote: I have to read a file content and i have to copy that content to buffer(char *buffer)...
So what's troubling you? Are you using C, C++, VC++, or MFC? There are many solutions but you've not even provided a starting point for us to work with.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
how to write into a file to a particular loaction in vc++
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
See Seek/SeekToBegin/SeekToEnd of CFile
|
|
|
|
|
CFile::Seek()
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
deeps_cute wrote: how to write into a file to a particular loaction in vc++
what type of file... BInary or Text
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
When a file is opened, the file pointer is positioned at offset 0, the beginning of the file.
You can reposition this file pointer in a previously opened file. The Seek function permits random access to a file’s contents by moving the pointer a specified amount, absolutely or relatively.
|
|
|
|
|
Paresh Chitte wrote: When a file is opened, the file pointer is positioned at offset 0, the beginning of the file.
Every Question have Reason hidden behind it! seeking and positioning in Text file is mush easier the doing that in binary file. when data stored in file is of different length. my concern is only that!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
How to select an item from ListControl on mouse moving over it?
|
|
|
|
|
|
Use Following code,
void CMyListCtrl::OnMouseMove(UINT uFlags, CPoint point)
{
int nItem = HitTest(point, &uFlags);
if (uFlags & LVHT_ONITEM)
{
SetItem(nItem, 0, LVIF_STATE, NULL, 0, LVIS_SELECTED,
LVIS_SELECTED, 0);
}
CListCtrl::OnMouseMove(uFlags, point);
}
|
|
|
|
|
|
I have several projects in one solution, after i build one project and run(don't build other projects), it will always tell me: "These project configuration(s) are out of date ...", i don't want that information, how can i do.
I know in vs2003, there's no such project, but currently i don't want to buy vs2003, because it will need me extra money.
Anybody can help me, thanks
|
|
|
|
|
hi i have to check for the machine if its HP machine then i have to open a file named syslinux.cfg and search for the word acpi if it is not there i have to set as acpi = off . if it is acpi = off then i have to change it as acpi = off. i tried this i can find out the machine. the machine name will be hp or hewlett packard. how to read the file and write as acpi = off. can anyone help me
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
I dunno how on earth you check if it's HP.
iostream and fstream are the headers you need. Something like ifstream f("c:\whatevr\syslinux.cfg"); then you can read it any way you like ( i.e. use google to find a tutorial on the file streams )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
deeps_cute wrote: i have to check for the machine if its HP machine
.. need an optical scanner to "view" the "HP" logo on the CPU box?
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir?
Dr.Brad :Well,I just replied to everything Graus did and then argued with Negus for a bit.
|
|
|
|
|
yes i need to check it is HP machine or not. is there any function to get this
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
Hello! I get an unhandles exception message when debugging..here is the code. I can't figure out what the problem is.
U8* Yarray =0;
U8* Uarray =0;
U8* Varray =0;
Yarray = (U8*) malloc( W*H );
Uarray = (U8*) malloc( W*H );
Varray = (U8*) malloc( W*H );
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
...
*Yarray++ = Yval;
*Uarray++ = Uval;
*Varray++ = Vval;
}
}
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
U8* Dst = static_cast< U8* >( m_imgImgMap.GetBits() );
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
U8 r = static_cast< U8 >( *Yarray + (1.4075 * (*Varray - 128)) );
U8 g = static_cast< U8 >( *Yarray - (0.3455 * (*Uarray - 128)) - (0.7169 * (*Varray - 128)) );
U8 b = static_cast< U8 >( *Yarray + (1.7790 * (*Uarray - 128)) );
SET_RGB( Dst, x, y, r, g, b );
*Yarray++;
*Uarray++;
*Varray++;
}
}
pStatus->SetPaneText( 0, _T( "" ) );
fclose (pFile);
free(Yarray); <<unhandled exception="">>
free(Uarray);
free(Varray);
|
|
|
|
|
Try changing this:
Yarray = (U8*) malloc( W*H );
Uarray = (U8*) malloc( W*H );
Varray = (U8*) malloc( W*H );
to this:
Yarray = (U8*)malloc(W*H*sizof(U8));
Uarray = (U8*)malloc(W*H*sizof(U8));
Varray = (U8*)malloc(W*H*sizof(U8));
If you're using C++ you it would be better to use new and delete however. i.e.
Yarray = new U8[W*H];
Uarray = new U8[W*H];
Varray = new U8[W*H];
delete [] Yarray;
delete [] Uarray;
delete [] Varray;
Even better would be to use a std::vector .
Steve
|
|
|
|
|
Thanks for your reply, Steve.
It still gives the exception error..what could be the cause?
Is there any other way besides using vector?
I'd like to code it in c style.
|
|
|
|
|
My earlier suggestion is one problem, however there is another. You must free using the same pointer value returned by malloc .
This code ensures that this doesn't happen (underlined):
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
U8 r = static_cast< U8 >( *Yarray + (1.4075 * (*Varray - 128)) );
U8 g = static_cast< U8 >( *Yarray - (0.3455 * (*Uarray - 128)) - (0.7169 * (*Varray - 128)) );
U8 b = static_cast< U8 >( *Yarray + (1.7790 * (*Uarray - 128)) );
SET_RGB( Dst, x, y, r, g, b );
*Yarray++;
*Uarray++;
*Varray++;
}
}
Alter your freeing code so it looks like this:
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
free(Yarray);
free(Uarray);
free(Varray);
PS: C sucks. If you used C++ and std::vector s such problems would be far less likely to occur. 'static_cast' is not usable in C.
Steve
|
|
|
|
|
So, did you get it to work?
Steve
|
|
|
|
|
It didn't work, here's the rest of the code.. tried not freeing the arrays and it worked but then eventually, of course, the exception occured after I closed the application.
if ( m_imgImgMap.IsNull() ) {
m_imgImgMap.Create( W, H, 24 );
pDoc->m_img.BitBlt( m_imgImgMap.GetDC(), 0, 0 );
m_imgImgMap.ReleaseDC();
const int iPitch = m_imgImgMap.GetPitch();
U8* pDst = static_cast< U8* >( m_imgImgMap.GetBits() );
U8* Yarray = 0;
U8* Uarray = 0;
U8* Varray = 0;
Yarray = (U8*) malloc(W*H*sizeof(U8));
Uarray = (U8*) malloc(W*H*sizeof(U8));
Varray = (U8*) malloc(W*H*sizeof(U8));
// Yarray = new U8[W*H];
// Uarray = new U8[W*H];
// Varray = new U8[W*H];
FILE * pFile;
int y = 0;
int x = 0;
//convert rgb to YUV
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
U8 r = GET_R( pDst, x, y );
U8 g = GET_G( pDst, x, y );
U8 b = GET_B( pDst, x, y );
U8 Yval = static_cast< U8 >( r * .299 + g * .587 + b * .114 );
U8 Uval = static_cast< U8 >( r * -.169 + g * -.332 + b * .500 + 128 );
U8 Vval = static_cast< U8 >( r * .500 + g * -.419 + b * -.0813 + 128 );
*Yarray++ = Yval;
*Uarray++ = Uval;
*Varray++ = Vval;
}
}
for ( y = 0; y < H/8; y++ ) {
for ( x = 0; x < W; x+=8 ) {
const short v = g_psSlope[(y)*g_iBW + (x)];
int mag = 0;
if ( 0 < v && v < g_iBokehWidthTh ) {
mag = 1;
} else if ( g_iBokehWidthTh <= v && v < UNKNOWN_MARK ) {
mag = 1;
} else if ( v == UNKNOWN_MARK ) {
mag = 3;
} else {
mag = 3;
}
fprintf (pFile, "%d ", v);
//get block
short buff[64] = {0};
int i,j;
int k = 0;
for ( i=(8*W*y+x) ; i<( 8*(y+1)*W+x ) ; i+=W ){
for ( j=0 ; j<8 ; j++ ){
buff[k] = Yarray[i+j];
k++;
}
}
int i6;
for (i6 = 0; i6 < 63; i6++) {
buff[i6] = (buff[i6]>>mag);
}
//return block
k = 0;
for ( i=(8*W*y+x) ; i<( 8*(y+1)*W+x ) ; i+=W ){
for ( j=0 ; j<8 ; j++ ){
Yarray[i+j] = buff[k];
k++;
}
}
}
csMsg.Format( _T( "Rendering… %d%%" ), static_cast< int >( 100.0 * y / H ) );
pStatus->SetPaneText( 0, csMsg );
}
// convert YUV to RGB
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
U8* Dst = static_cast< U8* >( m_imgImgMap.GetBits() );
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
U8 r = static_cast< U8 >( *Yarray + (1.4075 * (*Varray - 128)) );
U8 g = static_cast< U8 >( *Yarray - (0.3455 * (*Uarray - 128)) - (0.7169 * (*Varray - 128)) );
U8 b = static_cast< U8 >( *Yarray + (1.7790 * (*Uarray - 128)) );
SET_RGB( Dst, x, y, r, g, b );
*Yarray++;
*Uarray++;
*Varray++;
}
}
pStatus->SetPaneText( 0, _T( "" ) );
fclose (pFile);
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
free(Yarray);
free(Uarray);
free(Varray);
}
|
|
|
|
|
Side step all these issues by caching the initial values and not changing them. i.e.
U8 * const Yarray_org = (U8*)malloc(W*H*sizeof(U8));
U8 * const Uarray_org = (U8*)malloc(W*H*sizeof(U8));
U8 * const Varray_org = (U8*)malloc(W*H*sizeof(U8));
Yarray = Yarray_org;
Uarray = Uarray_org;
Varray = Varray_org;
NOTE: The underlined const s mean that the pointers can't be changed so that any code that attempts to change them from the original values will produce a compiler error.
Any time you have code like this:
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
use this instead:
Yarray = Yarray_org;
Uarray = Uarray_org;
Varray = Varray_org;
Finally free the memory like this:
free(Yarray_org);
free(Uarray_org);
free(Varray_org);
You can drop the following code before the free s:
Yarray-=H*W;
Uarray-=H*W;
Varray-=H*W;
PS: Use std::vector s!!!!!
Steve
|
|
|
|
|
Still doesn't work..not a VC++ bug?
I don't know how to use vectors..
|
|
|
|
|
Can you post the latest code?
Steve
|
|
|
|