https://t.co/LJfh85y6OD
Binary Search is an algorithm that’s used to find out if a number exists in a list, and if so, what it's position in that list is. The strategy is to "divide and conquer", which makes it much faster and more efficient than checking every single number.
Doing some more exploration into C.
Quickly noticed you can’t use the assignment operator with strings like you can in Python or JavaScript.
char source[] = “Hello”;
char destination[6];
destination = source; ❌ not allowed
https://t.co/OPRZ89SbqV
Vibe coding your own solution instead of using a SAAS is like making burgers at home. You did it yourself, awesome! but you have to be real… was it better than the one at the restaurant? And when you factor in your time + tokens, what did it REALLY cost you? Also, the cleanup.
Only downside is strlcpy isn’t part of the standard C library. So if you don’t have access, just use strncpy. But strncpy won’t add a null terminator if the source is larger than n, so you’ll have to make sure you manually add it otherwise, you get undefined behavior.
Ok so another random piece of info about C. You can’t use the assignment operator with strings because they’re arrays. So for example:
char source[] = “Hello”;
char destination[6];
destination = source; ❌ not allowed
You can do it with their pointers…
but that only creates a shallow copy. Changing the source will reflect in the destination.
You have to use:
strlcpy(destination, source, sizeof(destination));
it’s available in the string.h header file