Run a program in a program - c

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.

Related

Implementing a simple code in Microsemis Soft Console

I would like to get into the field of FPGAs a bit. I currently have a PolarFire Everest Dev Board and would like to try something small on it for testing purposes. My current level is very low, i.e. complete beginner. My first working project was a counter that counts binary to 15 and outputs it via the LEDs of the board. Now I wanted to play with RISC-V. Unfortunately I can't find anything on the internet that meets my expectations and almost nothing is "beginner friendly". My current goal is actually just to implement something on the level of a Hello World program in C via the SoftConsole. Unfortunately I have no idea how to go about it. Can anyone help me or recommend a good entry on the internet? Most of the stuff is either unusable, requires licenses I can't get, or is simply no longer available (which happens to me quite often with PDFs from Microsemi).
Since I don't really know what I could do with it to start with, I don't have any code yet that I would like to include. The plan would actually be to create something where I also get feedback via the board that something has been done. Later when I have more understanding SRAMs should be managed with it.

How to jump back lines in Python and make it reatart

I am writing a code that makes you choose which part of the code to execute and then execute it.
But then I’d also like to be able to make people choose AGAIN which part of the code to execute.
Can anyone help?
The code works the only thing missing is a loop I guess but I have no idea how to write it…

C Program slowing down after a couple read-ins

So i have to write a C program for class, that solves a connect four like game, that roughly said resolves matches of same colored pieces, lets pieces above fall down, then checks again for matches, if no matches were found it drops the next piece and so on.
My given input is a text file, where each line holds information about the color and the x-position, where the piece is supposed to fall down.
My implementation is based on AVL-trees and my program works fine for inputs roughly up to 2.000.000 lines and solves it in about 3 seconds.
One bigger example file i have to solve is roughtly 2.600.000 lines long but doesnt terminate.
The program reads in about 1.000.000 lines per second but right after about the 2.000.000 mark its slows down tremendously and only reads in a couple 100 lines per second.
Its one of my first "bigger" projects and has about 900 lines of code, so i dont see the point in posting it here (unless someone really wants to see it)
I am really clueless what the cause could be, so maybe someone of you has an idea or can point me in a direction for things i have to look out for.
Add logging with timestamps to spot where the slowdown occurs. You need to isolate the code that has the performance issue.
The first step to getting better is to measure where you currently are. Once you know how long the current process takes, you can decide if a change you make helps, hurts or makes no change.
There's a vast world of software optimization, look around for expensive loops. Read up on big oh notation. If you have a loop that processes a loop that processes a loop O(n^3), what seems fast with 100 iterations each can slow down dramatically when each loop is a million.
If you have a performance profiler it can help organize the timestamps from the logs it creates so that the code that's taking the most time is highlighted. Many times what happens in cases like this is that something that seems good enough when you start out isn't good enough once you start to scale.
Nobody says you have to add log to every single line of your source code. That can be overwhelming. Figuring out what you don't have to focus on can be very helpful.

Is there a way to print something in console that doesn't scroll down? (In C)

Well, maybe if I offer a little context this will be more understandable.
I want to print "Inventory" in the first line of my main, but I don't want "Inventory" to move from its place, so, while the rest of my commands show in console, and will scroll down, this particular line "Inventory will stay in its place."
http://i.stack.imgur.com/hVItr.png
I'm not sure if this can be done in C
This is quite hard in plain C due to how the console works.
There is, however a library that has done everything for you: NCurses: http://www.gnu.org/software/ncurses/

How to view variables during program execution

I am writing a relatively simple C program in Visual C++, and have two global variables which I would like to know the values of as the program runs. The values don't change once they are assigned, but my programming ability is not enough to be able to quickly construct a text box that displays the values (I'm working in Win32) so am looking for a quick routine that can perhaps export the values to a text file so I can look at them and check they are what they ought to be. Values are 'double'.
I was under the impression that this was the purpose of the debugger, but for me the debugger doesn't run as the 'file not found' is always the case.
Any ideas how I can easily check the value of a global variable (double) in a Win32 app?
Get the debugger working. You should maybe post another question with information about why it won't work - with as much info as possible.
Once you have done that, set a breakpoint, and under Visual C++ (I just tried with 2010), hover over the variable name.
You could also use the watch window to enter expressions and track their values.
If your debugger isn't working try using printf statements wherever the program iterates.
Sometimes this can be a useful way of watching a variable without having to step into it.
If however you wish to run through the program in debug mode set a breakpoint as suggested (in VS2010 you can right click on the line you want to set a breakpoint on).
Then you just need to go to Toolbars -> Debug Toolbar.
I usually like to put #ifdef _DEBUG (or write an appropriate macro or even extra code) to do the printing, and send to the output everything that can help me tracking what the program's doing. Since your variables are never changing, I would do so.
However, flooding the console with lots of values is bad imo, and in such cases I would rely on assertions and the debugger - you should really see why it's not working.
I've done enough Python and Ruby to tell you that debugging a complex program when all you have is a printf, although doable, is extremely frustrating and takes way longer than what it should.
Finally, since you mention your data type is double (please make sure you have a good reason for not using floats instead), in case you add some assertion, remember that == is to be avoided unless you know 100% that == is what you really really want (which is unlikely if your data comes from calculations).

Resources