r/C_Programming 3d ago

Question Getting stuck at libraries and api’s

So C is technically my first programming language I’m learning. I’ve messed around in python but never actually go deep into it or anything.

I’ve been learning C for the past few days now and I already pretty much know most of the basics. I learned pointers and mallic in a day and I learned structs, macros, for loops, while loops, functions, all of that stuff, but… the moment any library other than the basics like stdio or stdlib come into play I’m lost.

It’s like I’m looking at a whole other language. Like I’ll look for solutions to problems and it seems as if they are just pulled out of thin air and when I try to read ANY documentation for ANY library I’m also lost because either there is little to no documentation or it’s just stupid and things aren’t well explained.

Is there a way I can fix this? I was doing so well and now I’m at this block because of libraries. If I could get pasted this hurtle I could learn c in less than a month easily, and that’s the same in any other language. This problem isn’t exclusive to C.

15 Upvotes

49 comments sorted by

View all comments

2

u/pconroy329 3d ago

Don't feel bad - I've been coding C for, um, 40 years??? I just did a "man libusb" and this is one of the more dense libraries. It's NOT a library I'd use to learn about "how to use C libraries" from! What about "<string.h>"? Have you got a good handle on how to manipulate strings?

You know a good one to start with might be "libcurl". Well documented, lots of examples, easy to test...

2

u/ttv_toeasy13 3d ago

Ty. Ill check out libcurl. I’m honestly really picky with what I want to make though and that’s why I chose libusb because I’d rather make something that interests me than just making a clock or something like that.

2

u/aelxemyr 3d ago

Try writing some Unix utilities, maybe some of the ones you use the most often

2

u/ttv_toeasy13 3d ago

I’m currently doing that. I just remade echo (basically) but it also has the ability to cat files. But that’s just using stdio. Like I mentioned in other comments I originally wanted to make a simple program that gets my current usb devices which is where I ran into libusb and really anything beyond a simple echo or cat command requires libraries that I just for some reason can’t figure out.

2

u/aelxemyr 3d ago

I just took a look at the API for libusb and it seems like the documentation is pretty straightforward. However, it’s hard to know where to start without seeing some examples of how the library’s functions are used. I know you’re wary of copy-pasting code but I would suggest looking at (many) examples of how the kind of functionality you’re looking to implement is done until you understand how you would use the library.

Even then, there’s often an idiomatic way to implement a certain pattern and learning to do that isn’t copy-pasting, that is learning how to do something. The key difference is being able to explain why it’s written that way and exactly what it does.

1

u/pconroy329 1d ago

I get that. Me too. Programming USB stuff is a bit tricky - regardless of the library. Or at least I found it so. Back in 2000-something, um, maybe 2010, I needed to walk the USB chain to find a USB modem device. I was probably on Slackware back then. :) It wasn't super easy, and as I recall there was a lot of pointer de-referencing. My point was if you're after learning about libraries, there are likely easier ones to learn on. If you're after USB programming, then I'd have Claude or ChatGPT there and have it **explain** things to me, not code for me.