First, decide what information of your game describes a "game state". In other words, what is the difference between a "new game" and what state the user currently is?
Examples of that are:
- Character's stats (Name, level, experience, strength, intelligence, money, etc)
- Quests (What quests have the user completed? What progress do they have on active ones?)
- Maps (Has the player visited a place before? Do they have fog of war that is explored next time they visit it? After the user has killed enemies on one stage, do they respawn or remain permanently dead?)
Once you have all this information down, it's time to write a file that includes all that information, which is going to be saved on the disc, so it remains there until someone removes it manually. You can pick a simple format like
var=value and save all data like this:
quest_kill_dragon=0 # assuming -1 is not started, 0+ started and current state
map_mountain_explored=0 # maybe if you go to a map for the first time a cinematic plays
map_mountain_enemy_2=-1 # -1 on enemy is that they are dead and won't respawn
Please note I used
# to display comments, but normally you wouldn't need comments as this file is not meant to be readable by humans. What data you want to save is up to you and what game you are making.
Alternatively you can use JSON to save data on a file, there are plenty of libraries online that help you do that. Unfortunately I haven't used any in the past, so I can't recommend any.
In case its needed, the manual of how to open/close files in C: GNU - Opening and Closing Files