Skip to main content
gamedev.net
🔒 Locked

Does CreateFile create plain text files??

Started by jamesweston29 Jun 20, 2000 at 8:26 PM 3 replies 350+ views
Original Post
jamesweston29
jamesweston29
Hi I have finally maganged to get the CreateFile funciton to work and write a file but I can only get it to write binary files. Does it write plain text files and allow you tp append them also?? Also below is the code I have used to wirte a binary file, the only way I could get it to work was to make the structure variable an array. Is this the proper way of doing it, to me it doesn''t seem right. I would appreciate any help, thankx. struct MapType { int nPlayer1XPos; int nPlayer1Ypos; int nPlayer2XPos; int nPlayer2Ypos; }; MapType map[1]; DWORD dwNumRead=0; HANDLE hFile=CreateFile("map1.dat",GENERIC_WRITE,0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(hFile,map,sizeof(MapType),&dwNumRead, NULL); CloseHandle(hFile);
Void
Void
If the filename is "map1.txt", I believe it should be written in text mode..
Marauderz
Marauderz
When you use WriteFile you''ll be writing the EXACT contents of the buffer, that would be all the INTEGER values of the files.

You''ve more or less got the basics pinned, usually I''d write a savefunction that just creates a file based on whatever data I give it.

If you want to be able to APPEND to the file don''t use the CREATE_ALWAYS flag, you should use OPEN_ALWAYS if you want to just APPEND to the file.

Anyway just to let you know, there''s no one RIGHT way how to store your data file the main thing is whatever the way YOU store it, you should know how to extract and organize the data within it.

FYI, if you want a format that is in plain text file which would allow you to edit them by hand if necessary, then try using the MS XML Parser, That''s what I use for my game.... although I never used it in VC++ yet, so I can''t tell you the specifics... just go thru MSDN.

-------------------------
-Now Working on Pokemon like Engine!
-------------------------
-Now Working on Pokemon like Engine!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.