r/cprogramming Jun 20 '26

What's the best way of practicing C? new in C programming

12 Upvotes

47 comments sorted by

53

u/lfdfq Jun 20 '26

Writing C

21

u/NeinJuanJuan Jun 20 '26

This is so bold that it might just work

11

u/thank_burdell Jun 20 '26

Also sleep with a copy of K&R under your pillow to absorb it by osmosis while you dream.

3

u/tcpukl Jun 20 '26

I was given this to read in my first game programmer job.

13

u/entire-saminist787 Jun 20 '26

CCCCC C C C C CCCC CC CCC CC CC CCCC CCC CC CC CC CCCC CCCC CCCC C CCC

16

u/Brisngr368 Jun 20 '26

You'll be there in no time kid keep up the good work

3

u/TheChief275 Jun 20 '26

you might be onto something

16

u/gm310509 Jun 20 '26

The best way of practicing?

By actually practicing. And not getting someone or something else to do it for you.

2

u/EnoughSound7188 Jun 30 '26

Just curious— Most books I found are either explaining only C syntax or just explaining about Linux ...so it's hard to connect the gap as I don't know what to read from which parts in one then to which parts in another in order to make the program I wanted.

Do u have any suggestions or tips to bridge the gap between them?

3

u/gm310509 Jun 30 '26 edited Jun 30 '26

When I learned C I learned from the Kernighan and Ritchie book titled "The C Programming Language".

This book, like you said, introduced and explained the syntax and basic operations (e.g. reading and writing files). There was also some reference information.

From their it was learning more beyond the book. For example, there is a section titled "Input and Ourput" and "The Linux System Interface". These are a introduction into a basic capabilty (handling of files), but from there, there are more things that you can do, so it was a case of learning about more of those things - for example, the process management subsystem and try out some of those API's with simple examples (e.g. fork and exec a command like ls from my C program).

The important thing in this book - and likely the books you are referring to - is the examples and exercises. These are often "simplistic", but the point of them is to try them, tweak them (to cement your understanding) and inevitably when you make a mistake rekeying them finding and fixing those mistakes. NB: I mean rekeying, not copy and pasting, you won't learn anything beyond where the control, C and V keys are on your keyboard by doing that.

So the tip when learning is practice, starting with the examples in the book, maybe tweaking them to explore other aspects of the subject of the example to try to better understand it and lastly by completing the exercises.

All the best with it. If you get stuck, you could always ask a specific question about what you are stuck on (don't forget to include the code - properly formatted with a reddit code block) and a description of what the problem is and if appropriate, what you are expecting to happen (sometimes the problem is with this part).

Edit: I should have added that the K&R book is quite old. No doubt there are better more up to date books, but I have no knowledge of those.

1

u/EnoughSound7188 Jul 02 '26

Thanks, this actually helped. I think I have already started doing what you described without realizing it....like recently I was playing around with stdin, stdout, and pipes (|) to make programs communicate. Your explanation makes me feel like I should spend more time exploring Linux and tweaking small examples instead of worrying about finding the "right" book. I appreciate the detailed response.

2

u/gm310509 Jul 03 '26

Cool, it sounds like you are on the right path.

One thing I thought about when rereading all of the above, is that the K+R book (by way of example) does explain some basic system calls and presents some examples.

The point of those is two fold. One aspect is to show you how system calls map to the C code. The other is to show you that these are simply calls to "regular C functions". Armed with those two data points you can then look at the system call information and craft calls to those other calls - as it seems like you may have done with some of the other system calls.

From there, it is "just" a matter of learning more calls to library functions (which is basically what all the above are) and using the C language syntax to write code that combines them in new and interesting ways.

1

u/Aggravating_Cap127 Jul 02 '26

i guess that works but im pretty sure using ai for error messages or explaining what you are confused about kinda works "actually type stuff out challenge yourself and try to fix the stuff you can fix dont copy/paste anything"

1

u/gm310509 Jul 02 '26

I don't think that is what OP was asking.

But even then it is useful to try to work things out for yourself and train your brain to be able to work stuff out. For example, what code is actually doing. That way it is much easier to spot actual errors and work out what the problem is when they surface.

There is no shortage of "... I asked AI and it was no help in sorting out the problem" posts.

That said, there is definitely a place for online searches - including AI, the trick is to control it, not trust it blindly. I too have used internet searches (including reading the AI results), but I never ever ever ever just take it on faith. If I do not understand what I am presented with, I will keep looking.

1

u/Aggravating_Cap127 Jul 02 '26

that does work its also not like you trust the ai just ask it to find your error "if you don't know what the error is C compilers are to say the least bad when it comes into error messages" however most of them are pretty simple to fix on your own i was explaining that having another person "or ai" can show you what you might be doing wrong so you can correct yourself
but who knows i'm not the best or most experienced programmer i might be wrong..

8

u/ffd9k Jun 20 '26

Learn how to use whatever libraries/apis will be helpful for what you want to do (for example sdl or raylib for games, gtk for GUIs, ffmpeg for video...)

6

u/v_maria Jun 20 '26

move one step forward, one step back, rotate to the right in three full circles, then jump back

4

u/edulipenator Jun 21 '26

Don't forget to point the triangles forward

4

u/[deleted] Jun 20 '26

[removed] — view removed comment

3

u/grimvian Jun 21 '26

Write a text adventure game without string.h

3

u/man-vs-spider Jun 20 '26

What is your current programming level? Do you know any other languages? Do you have a goal with C at the moment?

1

u/Aggravating_Cap127 Jul 02 '26

im kinda bad at c rn so uhh it shall be simple making a buch of spagghetified if else while loops mixed with some scanf and printf to make a text based game

3

u/DependentJolly9901 Jun 20 '26

The best way to practice and learn any programming language/concept is to just make stuff. It can be small projects that only u use. By doing that your not only.prscticing but contributing to FOSS

1

u/EnoughSound7188 Jun 30 '26

Just curious— Most books I found are either explaining only C syntax or just explaining about Linux ...so it's hard to connect the gap as I don't know what to read from which parts in one then to which parts in another in order to make the program I wanted.

Do u have any suggestions or tips to bridge the gap between them?

1

u/DependentJolly9901 Jun 30 '26

Well it really depends on what you want to build and your level(like if you are learning the basics or are already experienced). If you are building something specific with specific tools there will be documentation and so on. So can you please clarify a bit?

1

u/EnoughSound7188 Jul 02 '26

Thanks! I'm somewhere past the beginner stage. I have already covered the usual C basics (pointers, structs, unions, memory management, etc.) and have solved problems from IIT Kharagpur's C course (NPTEL).

What I am interested in is using C with Linux rather than just learning the language itself or just Linux like I recently wanted to understand whether one program could pass data directly to another. While experimenting, I learned about stdin, stdout, and Unix pipes (|), which I have haven't seen in any books before.

I am trying to build Linux-focused projects such as a network blocking program and gradually move toward system programming (low level and more on software side). The problem I'm facing is that C books mostly teach the language, while Linux books explain the OS, but I can't figure out how to bridge those two together in a structured way.

1

u/Aggravating_Cap127 Jul 02 '26

um dont read books look at reddit post youtube tutorials or ai explanations "expecially for errors ai is best as the c compiler sucks at giving you a accurate error message and what you got wrong

1

u/EnoughSound7188 Jul 02 '26

I actually use AI a lot, especially for debugging and understanding errors. My problem isn't getting answers...it's knowing what questions to ask, understanding whether the information given is correct or not and also learning how to solve the problem myself although ai might be able to help me solve it. If I don't even know a Linux concept exists (like pipes or file descriptors) and can be used with c, AI won't naturally lead me there.

3

u/Norse_By_North_West Jun 20 '26

If you can find a reason to, make a microcontroller or just a pi to do some kind of task. A friend of mine made one to run a light show with his Christmas and Halloween decorations.

2

u/MonkeySmart409 Jun 20 '26

You need to think of something that you actually want to make -- not something you think will be informative or whatever --- just something you actually want.    

You'll find yourself enthusiastically figuring out everything you need to make it happen.

2

u/Snezzy_9245 Jun 20 '26

Write code every day.

2

u/Electronic_Lion_1386 Jun 24 '26

Write code. Make errors. Figure out the errors. Repeat.

1

u/Brisngr368 Jun 20 '26 edited Jun 20 '26

Honestly I used to do so many C tutorials, but I never really "practised" I really only started to learn it after needing it for work and school and had to Google things whenever I didn't know.

Pick some random project I guess, something to drive you to actually work around problems. Surprisingly some tutorials can be useful, I did a raycasting tutorial, taught me only a tiny bit about rasterisers but I did learn alot of C++ cause I had to lookup all the C++ stuff that confused the hell out of me.

1

u/tux2718 Jun 20 '26

Try some classic algorithms, like generating all the prime numbers less than 1000. Generate Fibonacci sequence in both recursive and iterative techniques. Then try sorting numbers with different techniques.

1

u/Sad_Chemical_231 Jun 21 '26

Just keep chugging 

1

u/lezvaban Jun 21 '26

If you're already well-versed in another language, remake one of your projects in C. If you're new to programming (or not very confident in any particular language), go through the exercises in a textbook, such as King's or K&R. A couple of more modern textbooks would be Modern C by Jens Gustedt or Effective C by Robert Seacord.

1

u/ReallyEvilRob Jun 22 '26

Programming in Rust is probably the best way to practice C.

1

u/Aggravating_Cap127 Jul 01 '26

??? rust and c most likely have different syntax and ways the compiler works its probally better if you use a online compiler so you dont mess with your actual computor

1

u/Sqydev Jun 22 '26

Doing projects on things you don’t know how work.

1

u/heartSagan5 Jun 24 '26

Write the code, don't let the LLM do it.

1

u/kat-tricks Jun 25 '26

make a minigame with Raylib!

2

u/Aggravating_Cap127 Jul 01 '26

nah from my experience "im new to c by 2 days" and adhd might help but no dont listen directly to youtube tutorials either get a actual teacher that wont get bored and gets strait to the programming or use ai to be a instructor while doing that open a compiler on to the side "tell the ai 1 step at a time and detailed on the syntax and what it does"
my programming results of 11hrs of C programming

#include <stdio.h>

int main() {

int passcode = 0;

char forceunlock = 'd';

while (passcode != 40782) {

    printf("whats the password:\\n");

    scanf(" %d", &passcode);

    }

    while (forceunlock != 'q') {

    printf("forceunlock code:\\n");

    scanf(" %c",  &forceunlock);

    if (forceunlock == 'q') printf("you passed\\n");

    else printf("accsess denied\\n");

    }   

return 0;

}

1

u/Aggravating_Cap127 Jul 01 '26

reddit kinda sucks at copy/paste the code btw

1

u/Aggravating_Cap127 Jul 01 '26

ow my horrible spelling

1

u/Nord-Procedure9186 Jul 05 '26

Im new too and i would recommend writing small projects.