|
Thanks for your reply
I just give you student as example ,but my data is very large and it may be very long way ,store that data in buffer n all..
|
|
|
|
|
SetFilePointer is the correct way to do it.
Before that you must open the file as GENERIC_READ|GENERIC_WRITE since you want to do both.
Each record in your case will take up sizeof(Student) bytes.
So it is just a matter of multiplication to find the offset of the record to modify.
So do a SetFilePointer to that offset with move method as FILE_BEGIN .
Then do a WriteFile with the new record.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
i also try to do same but it was not write there plz see code
ServerHandle = CreateFile ( L"server.dat" ,
GENERIC_READ | GENERIC_WRITE ,
FILE_SHARE_WRITE ,
NULL ,
OPEN_EXISTING ,
0 ,
NULL ) ;
if ( ServerHandle == INVALID_HANDLE_VALUE )
{
return ( 1 ) ;
}
ReadFile ( ServerHandle , & finfo , sizeof ( struct ServerFileInfo ) , &BytesRead , NULL ) ;
FilePointer.QuadPart =-sizeof(UpdateInfoOnServer);
for (i=0;i<finfo.NoUpdates ;i++)
{
ReadFile ( ServerHandle , & UpdateInfo , sizeof ( struct UpdateInfoOnServer ) , &BytesRead , NULL ) ;
if((UpdateInfo.IsApproved==1)&&(UpdateInfo.IsDownloaded==0) )
{
for(j=0;j<UpdateInfo.NumberOfPatches ;j++)
{
PatchFileID=UpdateInfo.PatchFileID[j] ;
iTmp=DownloadByPatchFileID();
if(iTmp==1)
{
return 1;
}
}
UpdateInfo.IsDownloaded=1;
SetFilePointerEx ( ServerHandle , FilePointer, NULL , FILE_CURRENT ) ;
WriteFile ( ServerHandle , & UpdateInfo , sizeof ( struct UpdateInfoOnServer ) , &BytesWritten , NULL ) ;
}
}
/////////////////////////////////////////////
where i make mistake..plz tell
|
|
|
|
|
You should be using your debugger here.
Set a breakpoint and single step through the code.
You'll surely catch the error.
And also you need to check return values of those APIs that you're calling.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
but logically are this things correct?
LARGE_INTEGER FilePointer ;
FilePointer.QuadPart =-sizeof(UpdateInfoOnServer);
SetFilePointerEx ( ServerHandle , FilePointer, NULL , FILE_CURRENT ) ;
|
|
|
|
|
as Cedrice said, unless you are going to have many people modifying the data at once; in which case you should store all the data in a database, and not worry about files at all.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
ashish8patil wrote: SetFilePointer
That sounds about right. Maybe you can tell us why you weren't able to use that? Because the following program, based on your (syntactically incorrect) code fragments, compiles and runs successfully. Here's a hint - check function returns values and GetLastError[^].
#include <Windows.h>
struct Student
{
int Marks;
int RollNo;
};
struct Student sobj;
int main()
{
HANDLE hFile = CreateFile("a.a", GENERIC_READ|GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
for(int i=0;i<10;i++)
{
sobj.Marks=10*i;
sobj.RollNo=i;
DWORD written;
WriteFile ( hFile , &sobj , sizeof ( sobj ) , &written, 0);
}
int i = 3;
sobj.Marks=5*i;
sobj.RollNo=i;
SetFilePointer(hFile, sizeof(sobj)*i, 0, FILE_BEGIN);
DWORD written;
WriteFile ( hFile , &sobj , sizeof ( sobj ) , &written, 0);
CloseHandle(hFile) ;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi guys,
I am developing a MDI application (VS-2008) using dockable panes. mostly things are working fine but there is a problem when the pane is set to Autohide.
As it hides it, if there are more than one panes there autohidded, only the caption of one which is active, apears and the icon of all other apear. I think i did somthing wrong when creating the pane or i'll need to set its some property but have no idea.
Please help
Thanks in advance
Harsh Shankar
|
|
|
|
|
hello,
i want to copy the content of ip control and add it to a list control. so try to do this ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, LPCTSTR(m_M1));
}
it compiles without any error but when i run it and click ok, it shows the error ---
Unhandled exception at 0x746bc348 in server_side_mfc.exe: 0xC0000005: Access violation reading location 0x00000017.
i also tried ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
sprintf_s(ss, "%s:%s:%s:%s", m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, (LPCTSTR)ss);
}
error ---
Unhandled exception at 0x5cd3e9ee (msvcr90d.dll) in server_side_mfc.exe: 0xC0000005: Access violation reading location 0x0000006f.
i also tried something like this which is working without any problem ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, _T("ABC"));
}
please help.
|
|
|
|
|
rahuljin wrote: void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
sprintf_s(ss, "%s:%s:%s:%s", m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, (LPCTSTR)ss);
}
You cannot simply typecast a char to LPCTSTR.
So use TCHAR ss[20] instead.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
thanks. but then how will i use ---
sprintf_s(ss, "%s:%s:%s:%s", m_M1, m_M2, m_M3, m_M4);
|
|
|
|
|
_stprintf_s(ss, _T("%d:%d:%d:%d"), m_M1, m_M2, m_M3, m_M4);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hello! I've developed an MFC application with VC++6.0. It still works for Vista32, but when I try to move a file to the recycle bin using SHFileOperation on Vista64 then I get the error code 120(ERROR_CALL_NOT_IMPLEMENTED). I know for Vista I should use IFileOperation, but I'm still using VC++6.0. Is there any way to move files to the recycle bin on Vista64 using VC++6.0?
Kind regards
Marcus
|
|
|
|
|
|
Wow! This is unawaited A long time ago somebody told me that the PSDKs from 2002 and later don't apply to VC6 any more. Therefore I'm still using the Oct. 2001 version. Does the latest SDK really compile for VC6? Thank you very much for your help!
Kind regards
Marcus
|
|
|
|
|
I really don't know.
You should try it and let me know.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Then I fear that it won't work. I'm just reading the release notes and they state that the current SDK only applies for VS2005 and VS2008. Anyway, thanks for the hint.
Kind regards
Marcus
|
|
|
|
|
Sorry about that. Didn't see that myself.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Doesn't matter. This confirms my feeling again that someday I have to buy VS20xy
Kind regards
Marcus
|
|
|
|
|
|
David, thank you very much for pointing me out that there is a more recent SDK for VC6. The service pack I already have.
Kind regards
Marcus
|
|
|
|
|
oBJECT:
To copy the data stored in a file along with their respective line numbers.
CODE:
#include<stdio>
#include<string>
#include<stdlib>
main()
{
int lno=1,n=0,x=1;
char ch[80];
FILE*fp;
fp=fopen("imp.txt","rb");
if (fp==NULL)
{puts("Cannot open file");
exit(1);}
printf("01 ");
while(1)
{
ch[n]=fgetc(fp);
n=n+1;
if (ch[n-1]==EOF)
break;
else if (ch[n-1]!='\r')
{
printf("%c",ch[n-1]);}
else if (ch[n-1]=='\r')
{x=x+1;
printf("\n0%d ",x);}
}
fclose(fp);
}
DATA STORED IN THE FILE:
hello raza here
how are you
PROBLEM:
Output is coming to be as following.
01 hello raza here
02
how are you
It should be
01 hello raza here
02 how are you
Now although i am reading the file in the binary mode, even then it is converting the
carriage returns into new lines! Why?
Also when i open the file in text mode the output is
01 hello raza here
how are you
|
|
|
|
|
Lines in files are terminated by "\r\n". You still seem to print out the "\n" after handling the "\r".
Kind regards
Marcus
|
|
|
|
|
Razanust wrote: It should be
01 hello raza here
02 how are you
int main()
{
int iLine = 0;
FILE* pFile = fopen("MyFile.txt", "r");
if(!pFile) return -1;
printf("%.2d", ++iLine);
while(true)
{
char c = fgetc(pFile);
if(c==EOF) break;
printf("%c", c);
if(c=='\n')
printf("%.2d", ++iLine);
}
return 0;
}
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
How To Find Number of processors Present in the CPU ?
How to Find Number of Cores Present in the CPU ?
Is any possiblity to find Number Cores and Number of Processors ? (Is any difference ) ?
|
|
|
|
|