| Post Reply | RetroFed Forum Forum Index » C Programming Language |
| Author | Message | ||
|---|---|---|---|
printf("%s", name);
piefed.blahaj.zone
akunohana@piefed.blahaj.zoneJoined: 2026-03-30 |
Good day! (Yes to all interpretations thereof.) I am a beginner at C, studying on my own because it's fun and my goal is to "simply" gain a better understanding of how machines work under the hood. I just successfully wrote a bidirectional Celcius/Fahrenheit converter that also takes some user input. As a next step, I would like to save conversion history. Do I have to save to a file outside the program or can I temporarily save history in a variable or an array and give the user the choice to check history by displaying the contents of that variable/array? If the answer is saving to an outside file, then I digress, as this is next on my "curriculum" (still self studies). If the answer is that I can save previous input into variables or an array, how do I make a - for instance - Also, if this is more advanced than what I am make it sound like, please let me know, and I'll let it be for the time being.
|
||
| 9 Original | |||
|
mcmodknower
programming.dev
mcmodknower@programming.dev Joined: 2023-07-22 |
For saving the history inside of one program run, an array is enough. You can already print the last conversion by reading the value of
For a longer history you need some extra places to store the numbers. if you use an array, you need to store the length of the history too, since c does not store how far into the array you have written.
PS: the
|
||
| 4 | |||
lime!
feddit.nu
lime@feddit.nuJoined: 2024-08-21 |
you can absolutely save history in an array, but depending on how you want to do it, it can get very complex for a beginner. the absolutely easiest way to go about it with how you've structured the program so far is making global arrays of just numbers, one for C->F conversions and one for the other way round. you also need to keep track of where in each array you are so you don't go out of bounds. this requires minimal changes.
and update your input handler:
and then when you want to see the list results, you do
this will of course not be in order of insertion, and if you want to show more than just the numbers you need to do some tinkering. this is however a great jumping-off point to talk about many different concepts:
sorry if my formatting is off, i did this on my phone... |
||
| 3 | |||
|
mcmodknower
programming.dev
mcmodknower@programming.dev Joined: 2023-07-22 |
For saving the history inside of one program run, an array is enough. For saving the history over multiple program runs (over closing by typing and invalid character or ctrl+c and restarting it), you would need to store it in a file. You can already print the last conversion by reading the value of f_value/c_value without writing to it (note that if no conversion of that type has happened befor...
some things seem to have duplicated in there, i will clean it up now. |
||
| 2 | |||
printf("%s", name);
piefed.blahaj.zone
akunohana@piefed.blahaj.zoneJoined: 2026-03-30 |
you can absolutely save history in an array, but depending on how you want to do it, it can get very complex for a beginner. the absolutely easiest way to go about it with how you've structured the program so far is making global arrays of just numbers, one for C->F conversions and one for the other way round. you also need to keep track of where in each array you are so you don't go out of ...
Thank you for the examples, the explanation and the FANTASTIC extra concepts! This'll keep me busy for some time! :) |
||
| 3 | |||
printf("%s", name);
piefed.blahaj.zone
akunohana@piefed.blahaj.zoneJoined: 2026-03-30 |
For saving the history inside of one program run, an array is enough. For saving the history over multiple program runs (over closing by typing and invalid character or ctrl+c and restarting it), you would need to store it in a file. You can already print the last conversion by reading the value of f_value/c_value without writing to it (note that if no conversion of that type has happened befor...
Woa! Thank you so much for using my embarassingly amateurish program to exemplify! This was really easy to read and understand! I'll play around with this for a while! :) |
||
| 5 | |||
lime!
feddit.nu
lime@feddit.nuJoined: 2024-08-21 |
Thank you for the examples, the explanation and the FANTASTIC extra concepts! This'll keep me busy for some time! :)
i hope you get something out of it! C is a rabbithole. |
||
| 3 | |||
printf("%s", name);
piefed.blahaj.zone
akunohana@piefed.blahaj.zoneJoined: 2026-03-30 |
i hope you get something out of it! C is a rabbithole.
Thanks! Ultimately, down the road, I want to try Assembly and then those languages that give CPUs instruction sets. I am interested in the borders where readable code turns into binary. I just chose C to begin with because I was influenced by Linux and a colleague who used to work with C many years ago. |
||
| 2 | |||
lime!
feddit.nu
lime@feddit.nuJoined: 2024-08-21 |
Thanks! Ultimately, down the road, I want to try Assembly and then those languages that give CPUs instruction sets. I am interested in the borders where readable code turns into binary. I just chose C to begin with because I was influenced by Linux and a colleague who used to work with C many years ago.
ah fun! have you checked out ben eater's ongoing youtube series of building a breadboard computer? he's selling kits that allow you to follow along from hardware through binary, assembly, to BASIC and C. well worth a look imo. |
||
| 3 | |||
| Post Reply |
Back to top |