| Post Reply | RetroFed Forum Forum Index » C Programming Language |
| Author | Message | ||
|---|---|---|---|
printf("%s", name);
piefed.blahaj.zone
akunohana@piefed.blahaj.zoneJoined: 2026-03-30 |
Thank you all for your kind, patient and educative responses when I obnoxiously post amateur questions! 💙 While I cannot make any promises because of how my brain works, I am almost ready to continue reading The C Programming Language, 2nd Edition. I just want to experiment a little bit with error handling, specifically how to handle wrong input (char VS. int, etc.) and also to learn to indentify code that runs the risk of overflow/underflow. Question: what errors do you recommend checking for and handling? Meanwhile, thank you all! 🥰
|
||
| 10 Original | |||
pelya
lemmy.world
pelya@lemmy.worldJoined: 2023-07-03 |
|
||
| 3 | |||
|
avidya
programming.dev
avidya@programming.dev Joined: 2026-05-10 |
Did you know that
is the same thing as
And an idom in C would be to define a constant for the size like this
|
||
| 2 | |||
printf("%s", name);
piefed.blahaj.zone
akunohana@piefed.blahaj.zoneJoined: 2026-03-30 |
Did you know that int history[10] = {0,0,0,0,0,0,0,0,0,0}; is the same thing as int history[10] = {0}; And an idom in C would be to define a constant for the size like this enum { HISTORY_MAX = 10}; int history[HISTORY_MAX] = {0}; int history_limit = HISTORY_MAX;
Cool! Thanks! I did read somewhere that if I'm certain that a variable isn't going to have to change its value throughout the program, then it's better to make it a constant. Out of security concerns? Anyway, thank you so much! 🥰 |
||
| 1 | |||
|
vanillama
programming.dev
vanillama@programming.dev Joined: 2026-05-11 |
Cool! Thanks! I did read somewhere that if I'm certain that a variable isn't going to have to change its value throughout the program, then it's better to make it a constant. Out of security concerns? Anyway, thank you so much! 🥰
It's in case you have to change those values later, you will probably miss one instance and get issues down the line. It also makes it more readable for other people (or yourself in a few months lol) |
||
| 2 | |||
| Post Reply |
Back to top |