|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hi i have the follwoing code but i am experiancing a lot of problems. I am to read a specific number of bytes (Size_of_the_file) from a fileand store them in a newly created file (OUTPUT_FILE).
I seem to be experiancing a number of errors regarding the use of my own variable for file paths in the CreateFile and WriteFile functions and the buffer. can anyone see where ive gone wrong? Code:
// Creating a file. OUTPUT_FILE contains a string for the path and file name
HANDLE FileCreate;
FileCreate = CreateFile("OUTPUT_FILE", GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
char buffer[Size_of_the_file]; //buffer set to size of variable 'Size_of_the_file'
Reading_file.seekg (start_byte,std::ios::beg) ; //positiong the ReadFile funstion at the correct place in the file to start
Reading_file = ReadFile("C:\\temp\\usbimage2.txt", &buffer, nBytesToRead, Size_of_the_file, NULL) ; // Reading file
// Check for end of buffer. If complete write to OUTPUT_FILE
if (Reading_file && nBytesRead == 0, )
{
WriteFile(OUTPUT_FILE, buffer, nBytesToRead, numBytesWritten)
}
thanks |
| Sponsored Links |
|
|
|
|||
|
You're using CreateFile to open a file called "OUTPUT_FILE" instead of using the contents of OUTPUT_FILE as the file name. Just get rid of the quotes in the third line and you'll be fine.
|
|
|||
|
I also spotted several other problems:
(1) You're destroying the file handle by setting the read to the return value of ReadFile. Code:
Reading_file = ReadFile("C:\\temp\\usbimage2.txt", &buffer, nBytesToRead, Size_of_the_file, NULL) ;
//should be
BOOL bSuccess = FALSE;
bSuccess = ReadFile(Reading_file,&buffer, Size_of_the_file, &nBytesToRead, NULL) ;
Code:
WriteFile(OUTPUT_FILE,&buffer, nBytesToRead, numBytesWritten) //should be WriteFile(FileCreate,&buffer,nBytesToRead,&numBytesWritten); |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SecurityAudit | vinay | Visual Basic Programming | 27 | 01-07-2008 01:14 PM |
| multi-pass preprocessing | kenna | C and C++ | 11 | 08-14-2007 11:45 AM |
| Reg Fucntion pointers | sowmi | C and C++ | 9 | 07-29-2007 04:29 AM |
| small help in this generator function plz | SamehSpiky | C and C++ | 3 | 06-22-2007 12:47 PM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |