0

So, I'm wondering if there's a way that I could have a program run in c, and when it finishes, to call and run a second program right after.

Basically, this is for a text-adventure thing, and I'd like it to run in segments, partly so that the code doesn't get huge with a ton if if-statements and all that, and partly so that I can have like a faux checkpoint system so that you can pick up sorta where you left off.

That, or a way to save your progress somehow. I couldn't come up with anything on exactly how to do that, but I know it's possible. I just don't really know what I'm doing yet. Forgive me if the above question(s) are really simple.

hego64
  • 345
  • 1
  • 5
  • 17
  • They're not simple questions; they're very broad questions, though. Have you code up any of your adventure? How are you going to maintain consistency between segments? Presumably, as you transition from one segment to another, the players don't lose their scores or goods found, etc. So you need to know how you're going to pass that data between segments. Database? File? Either could work. Will you be dealing with only a single user at a time, or could there be multiple users? In POSIX environments, you can use one of the `exec*()` family of functions to execute a new program. – Jonathan Leffler Jan 30 '17 at 22:47
  • One user at a time, and I had figured that if I was going to go with several segments, that I would just use a file to save player data instead of an array, which I would probably use if I was sticking to one giant file. – hego64 Jan 30 '17 at 22:49
  • How are you going to decide which segment to start when your user restarts the game? – Jonathan Leffler Jan 30 '17 at 22:52
  • I had thought about some kind of megamanesque system where you get a password at 'checkpoints' so, say, after every one or two segments you get a password that you can put in in the main starting point that would jump to the start of the segment you left off on. I'm assuming that's feasible. – hego64 Jan 30 '17 at 22:55
  • Should I use exec or system? What's the difference? – hego64 Jan 30 '17 at 23:11
  • 1
    The difference is that `exec*()` replaces the current process with a new program — a different program is started (or the same program is restarted) — whereas `system()` temporarily suspends the current program while another one runs, only resuming when the second finishes. Behind the scenes, `system()` is typically implemented on POSIX systems with `fork()` and `exec*()` doing the hard work. – Jonathan Leffler Jan 31 '17 at 00:12

0 Answers0