CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Posts
    336

    WriteFile/ReadFile repeat last lines

    Hi

    Code:
    	do
    	{
    		bReadSuccess = ReadFile( hFile, strBuffer, sizeof(strBuffer), &nRead, NULL);
    		bWriteSuccess = WriteFile( hFile2, strBuffer, sizeof(strBuffer), &nWrite, NULL);
    	}while(bReadSuccess && bWriteSuccess && (nRead > 0));
    a.txt's last line is:
    315614,05r re regf

    b.txt's last lines are:
    315614,05r re regf
    315614,05r re regf
    315614,05r re

    What is wrong with that loop?
    Thanks.
    Last edited by sawer; April 6th, 2009 at 10:59 AM.

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: WriteFile/ReadFile repeat last lines

    nRead doesn't has to be sizeof(strBuffer) if the buffer isn't fully filled, this probably creates the wierd lines. You are writing more that you read.
    Last edited by Skizmo; April 6th, 2009 at 11:07 AM.

  3. #3
    Join Date
    Sep 2005
    Posts
    336

    Re: WriteFile/ReadFile repeat last lines

    Understood.
    Solved it:
    Code:
    	do
    	{
    		bReadSuccess = ReadFile( hFile, strBuffer, sizeof(strBuffer), &nRead, NULL);
    		bWriteSuccess = WriteFile( hFile2, strBuffer, nRead, &nWrite, NULL);
    	}while(bReadSuccess && bWriteSuccess && (nRead > 0));
    Thanks
    Last edited by sawer; April 6th, 2009 at 11:16 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured