Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Does CreateFile create plain text files??

This topic is 6539 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);

Share this post

Link to post
Share on other sites
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!

Share this post

Link to post
Share on other sites
Guest Anonymous Poster

MapType map;

and then

WriteFile(hFile,&map,sizeof(MapType),&dwNumRead, NULL);

The second parameter to WriteFile should be the memory address
of the start of the data you wish to write to file. The way you
had it achieved the same result by declaring map as an array
and then you passed the address of the first element of the
array to WriteFile.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!