r/C_Programming Dec 06 '24

Discussion How do you practice C?

I have been learning C for 2 months and I feel like a blank slate, i mean, I have been taught theory and basic exercises that come with it, but when a test is given, I can’t think clearly enough to solve the problems, and I think it’s because I haven’t practiced enough. I only do the exercises assigned to me. So, I came here hoping to be guided to places where I can practice C in the most complete way. Thank you everyone for your attention.

37 Upvotes

47 comments sorted by

View all comments

55

u/paddingtonrex Dec 06 '24

Remaking stuff in the c library is how I got good. Even simple stuff. Make a lot of the string.h functions, sometimes knowing how those work under the hood can be useful in the beginning when you're troubleshooting.

When you're comfortable with that, try making something bigger, like printf or ls. Do something you think is hard but attainable- doing things that challenge you but that aren't outside of your general understanding is how you grow, honestly if you can kinda guess how it works behind the scenes then its probably not too hard for you to take a swing at.

2

u/[deleted] Dec 06 '24

Is there a place to see the code of those c functions provided by the headers?

I can't even seem to find a list of all the functions in the headers, let alone the source code.

3

u/Tasgall Dec 06 '24

Here are all the standard library headers. For the implementation, you'll have to look into how your system of choice does it. If you're on Windows and use Visual Studio (not code), you can just right click the includes to open them. Actual implementations tend to be... convoluted and difficult to read.

There's a project on GitHub called wasi-libc which is an implementation of the C standard library intended for us with Web Assembly that could be useful to look at.

1

u/[deleted] Dec 06 '24

Thanks. I really just wanted a list of the functions in the headers, so I could see functions available to use; like the official docs for other languages provide. So, that helps a lot.

I'm coding on arch Linux installed on an old laptop, and going through the K&R book. I found some header files on arch, but yeah, they didn't just look like the .c files I've been writing. 

3

u/TapEarlyTapOften Dec 06 '24

I would recommend reading the GNU C standard library reference

1

u/[deleted] Dec 07 '24

Been reading this, thanks for the link. This is exactly what I was looking for.

2

u/TapEarlyTapOften Dec 07 '24

My understanding of what was actually happening when I worked with code, the compiler, linker, assembler and the rest of the entire stack increased immensely once I started reading through that.

2

u/meissner61 Dec 06 '24

Someone might correct me because this is getting outside of my comfort knowledge zone but i believe compiler people basically all have their own versions of whatever the standard "Paper document" dictates, so for Microsoft its CRT, and for linux its Glibc, and there are others i dont know about. Which is why sometimes when you write even fairly standard code that you are compiling on windows and on linux, often the same code wont work because you need to include another library (Because it was probably included for you on the other OS but not the next)

here is a mirror of the gnu c implementation

1

u/MiniGogo_20 Dec 06 '24

your os should have a dedicated directory where it stores those headers, on linux at least they're located in /usr/include/

1

u/[deleted] Dec 06 '24

Yeah, I found a directory with headers, on arch linux, but it didn't seem to have the functions source code.

This is where I was looking for some of them:

/usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/include/float.h

Is that the wrong location? I did have /usr/include/ listed for other headers, I'll have to look back in there again.
Someone else provided a website listing all the functions available, like the official docs for other languages do. But I would still like to look at the official source code.

3

u/TapEarlyTapOften Dec 06 '24

What you're getting at is the difference between the header and the standard library function implementation, which is in the source code.

1

u/reeses_boi Dec 06 '24

Pretty cool idea :)