Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Great, now do the same in C, but for arbitrary long inputs (only limited by SIZE_MAX or memory).
This should keep you busy for an hour. -
klutch3895yThat's gonna be a good one, because I haven't the chance to do anything with it outside of some little tidbits here and there or reading about it
-
SomeNone7135y``strlen()`` in C counts the characters up to but excluding the terminal null every time. Don't use it inside a loop unless you must.
Your two conditions in the while loop are arguably the same. If the buffer is full of valid characters, it will not hold a terminal null, and both conditions may fail (depending on what comes after the buffer). -
SomeNone7135y@klutch You should probably refactor your ``caesarCipher()`` function to take a source buffer, a destination buffer, and a maximum length, then print the destination buffer in ``main()``. Unless you want to compete with whatever people post in /r/badcode…
Here's a little F# solution that I hacked up in about 15 minutes: -
klutch3895y@SomeNone Noted, thanks so much!!! I'm gonna throw that in my code notes as I carry on. I've never done anything with C, so I'm all ears! I wanna make sure when the time comes down the road I can squeak by just enough to get it done, but done right. I NEVER half ass stuff when it's the real deal.
Related Rants
-
xjose97x19Just saw a variable in C named like this: long time_ago; //in a galaxy far away I laughed no stop.
-
elgringo41Student - Teacher renaming .c to .exe make the program executable ? Teacher - Yes A group of people stand up...
-
Cyborg15A guy and a girl are in a Java seminar. Afterward, the guy approaches the girl and asks, "Hey gurrl, can I ge...
Great practice/skill sharpening idea for my fellow mad dogs that like to get down in multiple languages/syntaxes:
Pick something simple that won't cause too much stress, but will make you sweat a little bit and put up a good fight, ha!!!
For example, I picked the classic "Caesars Cipher" and picked 5 languages to create it in! I picked Dart, Java, Python, CPP, and C. Each version does the same thing:
1. Asks for a message
2. Runs the logic
3. Prints the message cipher.
4. To decrypt, you just run the same program again and enter the cipher text at the message input prompt. The message gets deciphered using the same logic an shows up as the original text.
The kicker:
Only dox/books allowed for reference. Otherwise it wouldn't push you to get better!!!
Python, C, and CPP were EASY, even with me never having used C before. I am great at using Dart, and that one really challenged me for some reason, but I finally got it. The previous 3 langs took less than 40 lines of code each (with Python being only 18 I believe). Dart actually took somewhere around 50, and Java took about 371784784. (Much love to Java though for real!)
Kinda boring as shit, but I gotta tell you it felt fuckin GREAT to look at all 5 of those programs after completing them, no matter how barbaric... especially when you complete 1 or 2 in a language you've never used or maybe felt really challenged by. Simple exercises that hold a lot of important, relatable logic no matter the subject is our lifeblood!!!
rant
python
c
exercises
books n stuff
tegrity
java
use ya noggin
dart
cpp