How to save stuff ?

First off I'm sorry about my stupid title. I sat here for 5 minutes thinking how to word it but everything sounded incorrect and stupid. =P

Ok, so I'm talking about saving things done in one execution of a program for use the next times it's run. For example, cash in blackjack, if you win 20k then you can close it and start off with 20k next time. I know that I can write it to a text file and then read it, but there has to be a way to do it without another file besides the .exe,..right? I dunno, I'm just curious.Thanks
nope.. you have to save it to a txt file, or some sort of binary file or something. You can't save it inside the exe itself.

Windows does give an option to write to the registry file (it stores the informtion under an area set aside specifically for your program). I've seen that before when working with vb a few years back. But I have no idea what the api calls would be to access that option in C or C++.
It would be very unadvisable to make any changes to the registry!! Particularly if you are an inexperienced programmer - which would be the case from your question.

Alan
Kinda in the same ball park question. What are the normal format do you guys use to save your data? Just basic text file, binary, dat? Or do you encrypt it or anything?
Data goes in binary, configuration goes in text.
Encryption is hardly ever necessary or practical. Usually mild obfuscation works just fine.
@AZlan LB
normally, it would be unwise to make changes to registry.. but what I am reffering to is meant for newbies. There is some api that can be called that would save application data to the registry under space that is set aside for that application and does not give access to anything outside of that space.

I remember using it with VB.. It was meant to be a replacement to using INI files, and in fact act like an INI file. I am unsure what the api call is, however that C and C++ could access it.

But in any case, it was a safe way to work with the registry as it only gave access to space that was allocated for that specific application. It wouldn't let you edit any other part of the registry.

VB6 has no built-in support for "ini files" API, while the existence of the GetSetting and SaveSetting functions, which behave like the above mentioned APIs but store informations in the Windows Registry (which was meant to be the Win32 counterpart of Windows 3.1 ini files) hint at the idea that what you need isn't an .ini file, but a bunch of registry keys.


Maybe it is only a VB6 thing. I thought the api would be available to C or C++ as well.

Edit: Ok, found an MSDN article on it. http://msdn.microsoft.com/en-us/library/ms838625.aspx This explains how to use the registry to save application data, there is even a c++ library available to help automate it.
Last edited on
First off I'm sorry about my stupid title. I sat here for 5 minutes thinking how to word it but everything sounded incorrect and stupid. =P

Ok, so I'm talking about saving things done in one execution of a program for use the next times it's run. For example, cash in blackjack, if you win 20k then you can close it and start off with 20k next time. I know that I can write it to a text file and then read it, but there has to be a way to do it without another file besides the .exe,..right? I dunno, I'm just curious.Thanks


Database
Text File
Binary File
Registry


Personally, most of the applications I write interface to databases for saving information.

You should write and post up an article on how to interface with databases for saving information Zaita. :)
I have to admit, that would be one article I would be very interested in reading. I've worked with mySQL in php and perl, but I'd love to learn how to work with a database on windows with c++.

Do I need to install a database server such as mySQL? can I access an ODBC database like the one Access uses? Lots of info I'd love to learn.
Somehow, I get the feeling that using a database to store program data and configuration is like using a flamethrower to light up a cigarette. It's just overkill.
Probalby the programs he mentioned doesn't just have a couple of configuration data or just a few lines of program data...

If you want to make a program for storing alot of information it will be much faster and easier to use a database that provides easy storage and search and inser queries through SQL...
Last edited on
Topic archived. No new replies allowed.