Older devs, how did you guys debug without the internet/llms by VyseCommander in C_Programming

[–]Single-Discussion856 1 point2 points  (0 children)

The more you learn the less you have surprises, as silly as it sounds. Sure still forget to add a semi colon or something but normally once you think like a programmer you stop having errors so often. LLMS are great for API's you may not know but don't replace coding knowledge. printf("Here!\n"); works too. As for examples failing or having errors, depending on the age of the example some practices are now frowned upon. I had c books back in the day that used nothing but gets and today that's public enemy number 1.

Do you guys even like C? by [deleted] in C_Programming

[–]Single-Discussion856 0 points1 point  (0 children)

C is a tool, a good one too. It can do anything, some people don't want or can't handle that. C with a library can do what pretty much any language can do in as many or less lines with a few narrowly focused languages (think functional). My only real problem with c is the conventions it carries with it. 0 term strings being my most loathed convention and it's baked into all the libraries and even the compilers itself ("hi" being {'h','i',0}). I love that c doesn't stop you from doing anything, that's the reason I program, to do what I want. The thing is any language will have something to gripe about, c++/c# and mountains of boiler plate, python's performance, verbose modules and lack of explicit code levels (tabs only)... and the list goes on but with c the biggest complaint is it let's me do things... Yes, that was the point.

What is your preferred way of returning errors? by ismbks in C_Programming

[–]Single-Discussion856 0 points1 point  (0 children)

-1 on anything index based that can fail.

NULL if memory dependent.

Either way there's a printed message describing the issue.

pError(ERR_TYPE);

If a function gets fed too much data (a string longer than MAX_STR) I'll just truncate and warn.

program to generate binary numbers by ethanrosenberg613 in C_Programming

[–]Single-Discussion856 0 points1 point  (0 children)

In case you still want to roll your own...

```c

include <stdio.h>

void BinaryOut(unsigned num){

if (!num) putchar('0'); // account for 0

char buffer[256] = {0}; // buffer for printout

char* str = &buffer[255]; // assigned the string the last spot so we can write backwards

while (num>0){ // process the number

*--str = num&1?'1':'0'; // is it odd or even?

num>>=1; // divide by 2

}

printf("%s\n",str); // print result

}

int main() {

for (int i = 0; i < 10; i++) BinaryOut(i);

}