| | |
data file help
![]() |
•
•
Join Date: May 2003
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by gilgamesh
i need to be able to add data to my .dat file without deleting my old data during a program run can anyone help me?
If this is a console app (DOS program) or UNIX program that outputs to standard output, you could redirect the output to your data file
program.exe >> datafile.dat
If this is a Windows program, you can use CreateFile with the following arguments
C Syntax (Toggle Plain Text)
HANDLE hFile = INVALID_HANDLE_VALUE; hFile = CreateFile("yourfile.dat", GENERIC_READ | GENERIC_WRITE, 0, // no file sharing NULL, // no security descriptor OPEN_ALWAYS, // creates if not found FILE_ATTRIBUTE_NORMAL, NULL); // No template handle
This returns a HANDLE that you can pass to ReadFile and WriteFile
Using SetFilePointer if you need to position to any part of the file.
C Syntax (Toggle Plain Text)
if (hFile != INVALID_HANDLE_VALUE) { DWORD bytesWritten; if (FALSE == WriteFile(hFile, dataBuffer, // data to write dataBufferSize, &bytesWritten, NULL)) // not using overlapped I/O { MessageBox(GetActiveWindow(), "Error", "Error", MB_ICONSTOP); } // will want to verify // bytesWritten == dataBufferSize }
Be sure to close the file with
C Syntax (Toggle Plain Text)
CloseHandle(hFile);
Hope this helps.
![]() |
Similar Threads
- Please help with data file and array (C++)
- Help creating a data file (C)
- input data from a file into an Array (C)
- Reading from external data file (C++)
Other Threads in the C Forum
- Previous Thread: Question
- Next Thread: Joystick driver
Views: 4415 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C
api array arrays bash behaviour binary binarysearch c++ char character code coke command conversion convert copy copypdffile createcopyoffile database decimal directory dude dynamic ebook error exec factorial fgets file fork function functions givemetehcodez global grade graphics hacking help.forensic homework i/o ide input insert int integer lazy libcurl library line linked linkedlist linux list lists loop malloc matrix memory mysql no-effort number output pass path pointer pointers power printf problem process program programming read recursion recursive recv research reverse roman scanf sequential sms_speak socketprograming spoonfeeding steganography strchr string strings strtok structures student system test turbo-c turboc unix user variable windows words





