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…
Related
I have been writing a program for multi-element diffusion. Because the method I am using is poorly optimized in MatLab, I have been programming in C, as that is fast for my purpose. I am, however, much more an engineer than a programmer.
The model consists of many functions and each of those functions I have tested separately for expected inputs. However, now that everything is together, my program gets stuck. Most likely in one of the (many) while loops.
If I can find which loop it gets stuck in, I can see if it gets a wrong input, or if I made a mistake in the loop itself that I missed during testing.
If it were simply looping a few times, I could add a print statement of sorts in each loop, but since it iterates a few million to more than a billion times, that won't work. And if I try to run it with just a few hundred iterations, the problem doesn't occur.
I was hoping that in the IDE there is an option to see which function is currently being executed, but I can't find it in the one I am using (Pelles C).
Is there an option in Pelles C (or if not there in another IDE) that shows which function is currently active? Or is there a different way to find where it gets stuck?
I have been trying to get the debugger to tell me where it is stuck, but even though it gives me a lot of information about things I have no clue about, it doesn't seem to tell me what I want to know.
Compile your program with -g flag and run it using gdb`
gdb ./test
whenever it gets stuck, run 'where' or 'bt' in gdb's command line, to find the exact line where it gets stuck. Also put -Wall flag, it will show all warnings.
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.
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/
I want gdb to dump the code it executes line by line. Just like step command as it shows the current line but I do not want do step through the entire code as it is too big.
So I want to automate it.
The reason I want to do this because my code behaves differently in two scenarios and I want to see where actually the diff arises so I plan to take dump for two different scenarios in two different file then take a diff.
I know it may not be the best way to debug something but trust me I have tried a lots of stuff to find the bug but no use and I think this can help me in a great way.
Thanks in advance !!
With GDB you can set breakpoints that will allow you to follow step by step the code in a specific area of your programm.
This may sound like a silly question but I could see no mention anywhere of this particular problem. Basically:
I want to execute a Lua script line by line, primarily to have the ability to pause/resume execution anytime and anywhere I want. What I do is simple: load a chunk with luaL_loadbuffer() and then issue a lua_pcall().
Thing is... How can I properly detect Lua blocks in order to execute them atomically?
For instance, suppose there's a function in the script -- by executing the file line by line with the method described above, I can't seem to have a way to properly recognize the function, and in consequence its contents are loaded and called one by one.
I can imagine that one solution would be to manually handle a stack where I push control keywords I can recognize in the script ("function", "if", "do", etc) and their corresponding "end" clause if I find nested blocks. Once I push the final "end" I call the entire block, but that sounds simply awful. Surely there must be a better way of doing this.
Hope it makes some sense, and thank you!
Please take a look at Lua coroutines to implement that functionality for scripting game entities. The idea is to yield the coroutine in the sleep() and waitforevent() routines you mentioned, and then resume later (e.g. after a timeout or event occurs).
Use lua_sethook().
Note that you probably do want to experiment with what exact hook call granularity you need. I'd recommend executing chunks of bytecode instructions instead. One really long line may contain many instructions.