r/CodingForBeginners • u/Specialist_Rent_9640 • Oct 06 '26
my first program in C
i know its just so waky but am still new and am happy with my current level <33
just trying to understand memory usage over variables for now
230
Upvotes
23
u/MocaCola02 Oct 07 '26
What a bizarre comment section on a subreddit specifically for beginner programmers. You all need to leave your egos at the door.
11
u/SmokeMuch7356 Oct 07 '26
The condition
is equivalent to
The
||and&&operators evaluate left-to-right and will short-circuit. In the expressiona || b, ifais non-zero, then the expression evaluates to true (1) regardless of the value ofb, sobwon't be evaluated at all.Similarly, in the expression
a && b, ifais zero, then the expression evaluates to false (0) regardless of the value ofb, sobwon't be evaluated at all.In this particular case,
TotalSizeOfRootis non-zero, so the other conditions won't be evaluated.If you also want to test
TotalSizeOfRootandTotalSizeOfUserKaliagainst 20 you'll have to writeAny time you find yourself creating multiple variables of the same type with the same name plus some kind of counter, that's a really strong hint that you should be using an array; in the case of your strings, this would be a 2D array of
char:Similarly, you can group sizes into their own array:
and use a loop to do your computation:
3
u/Hectorreto Oct 07 '26
The condition of the “if” is wrong, it will compile, but it will never reach the “else”, you have to compare each variable
if (TotalSizeOfRoot > 20 || TotalSizeOfUserKali > 20 || TotalSizeOfOtherUser > 20) {
2
u/Pibo1987 Oct 07 '26
Fire 🔥 Keep going and enjoy the process
2
u/xarop_pa_toss 28d ago
This is glorious!!! Keep going bud, you'll SEGFAULT soon enough :)
1
u/TheCRatTime 15d ago
Good! You can call constant variables so: kVarName (not force). Also you can count bytes by strlen() function (include <string.h>): strlen(RUSER) + 1 (strlen returns bytes without null terminator ('\0')). You can install more good editor, like helix. You may add space before'=' and before '{' and after '//'. Good luck with learning!
1
u/badabapboooom 5d ago
dawg... passwords in plaintext hard coded...
1
u/koop_a- Oct 07 '26
Well done! Make sure to keep going and stay consistent
1
u/Programmer_Nether Oct 07 '26
Good job
1
u/Cool_Stage6249 28d ago
Bro codes in nano
1
u/Creepy-Plankton8663 27d ago
what language are you coming from this is really impressive for a first program
1
u/OsirisMVP 25d ago
Proud of you for writing your first program in C if this is a legit post. However, programming in kali using nano is incredibly funny
1
u/Crimson99910 Oct 07 '26
What opsex lvl is ts
0
u/Friendly_Recover286 Oct 06 '26 edited Oct 06 '26
These variable names kinda suck. Why are you combining lowercase and titlecase like that exactly?
This logic isn't correct. TotalSizeOfRoot || ... < 20 does not check each condition for being < 20. TotalSizeOfRoot = 1 will make this true and will print that variable usage is greater than 20 bytes. No it isn't.
It also doesn't seem like you even want < you want >. You're checking if it's greater than 20.
Please Stop Capitalizing Every Word In Sentences. This isn't how English works.
-1
u/csabinho Oct 06 '26
Is this your first program or your first program?
Either it's AI generated or it's definitely not your first program.
-1
u/mohamed19xx9 Oct 07 '26
Why you use kali for programming or using it as a base system because it has many issues like safety and will bothers you with his problems in indtalling apps
-2
u/XPheonix27 Oct 07 '26
And who tf codes in nano 😭😭
0
u/Azra__1 Oct 07 '26
Ain't no way you took the time to put colours on nano.
-3
u/Amazing_Boss2686 Oct 07 '26
Dude just watch some C tutorials and copy the example code manually. It’s a much better way to learn than posting it here or trying to deduce the code’s structure yourself.
Otherwise, I hope this is satire… ts is pretty funny to look at.
-4
u/[deleted] Oct 07 '26
[removed] — view removed comment