this post was submitted on 22 Jul 2023
10 points (91.7% liked)
Learn Programming
1648 readers
1 users here now
Posting Etiquette
-
Ask the main part of your question in the title. This should be concise but informative.
-
Provide everything up front. Don't make people fish for more details in the comments. Provide background information and examples.
-
Be present for follow up questions. Don't ask for help and run away. Stick around to answer questions and provide more details.
-
Ask about the problem you're trying to solve. Don't focus too much on debugging your exact solution, as you may be going down the wrong path. Include as much information as you can about what you ultimately are trying to achieve. See more on this here: https://xyproblem.info/
Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
C is a language, and to get better at any language you need to practice it; meaning you need to program. Programing toy problems might not be a solid motivator because it sort of feels "useless". Creating things that will be used, by you or others, is likely to be a more driving factor. With that in mind I'd suggest you create a public repository and populate it with C utilities/library that you can use when you are writing C code; utilities that will save you time. The utilities/libraries will be ones that you write yourself.
What kind of utilities/libraries should you program? Hard to say not knowing your current ability. Let me try and generalize; I'd say C is a quite verbose language in the sense that to do some basic things you need more code to achieve a specific task. This is typically because the standard library will return any and all info about the system, and then you need to pick out exactly what you need from it.
For example, (this might be outside of your C knowledge but hang in there and ignore the details, just pay attention to the point). For example, if I had a network interface
eth0
on my linux system and I wanted to get the IP address of that interface from inside C, there is no straight forward function calledget_ip_by_interface_name(if_name)
. The closest thing is the functiongetifaddrs()
which creates and returns a linked list of structures of every interface and individual IP on the local system (for more info seeman 3 getifaddrs
). You then have to traverse the linked list, and compare the name you're looking for to the name of the interface. Then you have you check if the IP address is IPv4, IPv6, etc etc. That's a lot of work every time you need to just get an IP address of an interface. Had you a need for it, I would suggest you go and implement aget_ip_by_interface_name(name)
and have that in your own utility repository. Then when you are working on a project, you can go and use your own code. Here is an advanced example of where someone made crypto hashes and has them around. Don't get overwhelmed with this or even try to copy it, my point is do something like this that reflects what functions would make your life easier in your programming..So how will I know what type of utilities will help me? That's another question that depends on who is asking it. For me, when I work with C I do a lot of networking, so I have my own utilities that
check_interface_exists(if_name)
,get_ip(if_name)
,link_ready(if_name)
. For you, I would suggest working toward implementing thread-safe data structures. They are really handy to have around when programming and programming the data-structures you get good practice with the language. From your post it seems you have the basics down? You might be on a bit of a learning curve with mutexes but hey, you wanted to learn :)Common thread-safe data structures implemented in C typically include Queues, Stacks, and Hash Tables. Linked-list might be the easier of them, but a queue being more useful. Hash tables and binary trees are more advanced but also useful. You can tackle them in the following order of increasing difficulty.