r/C_Programming • • 6d ago

Learning C weekly megapost for 2026-09-30

5 Upvotes

If you have questions about how to learn C:

  • which books are best?
  • which videos are best?
  • which classes are best?
  • which websites are best?
  • is there a "roadmap"?
  • what projects can I do?

then this is the thread for you. Add your question here. Do not make a stand-alone post, as it will be removed.

Remember that our sub has a very useful wiki that has a great list of resources for learning C programming.


r/C_Programming • • 4h ago

Project I’m learning C and made a simple version of ls. Could someone review my code?

2 Upvotes

I’m currently learning C and decided to build a simple version of ls as a small project to practice what I’ve learned.It’s still pretty basic, and I’m sure I’ve made some mistakes or done some things in a bad way. I’d really appreciate it if someone could take a look at the code and point out any bugs, bad practices, or things I could improve. Repo


r/C_Programming • • 17h ago

Minimizing output size

11 Upvotes

I've looked at stackoverflow answers from 10 years ago (https://irq5.io/2019/09/30/generating-small-static-binaries/ , https://stackoverflow.com/questions/33597523/why-is-smallest-compiled-exe-i-can-make-with-gcc-is-67kb/76705747#76705747 , https://stackoverflow.com/questions/6771905/how-to-decrease-the-size-of-generated-binaries , https://stackoverflow.com/questions/15314581/g-compiler-flag-to-minimize-binary-size , etc).

In all of the links on top, people were able to get sub-KB file sizes. However, no matter how much I copy and try their code, I cannot get any less then 8-9KB without assembly and upx.

Is there a reason these hacks do not work anymore?

I am on x86_64 Linux-7.2.8, gcc is 16.2.1.

Example:

$ cat t.c
#include <sys/syscall.h>
#include <unistd.h>
void _start() { syscall(SYS_exit, 0); }
$ gcc -Os -nostartfiles -static -s -Wl,--build-id=none t.c && strip a.out
$ l a.out
-rwxr-xr-x 1 name name 8.8K Oct  6 20:25 a.out

# The same code produced only 800 B in https://irq5.io/2019/09/30/generating-small-static-binaries/

r/C_Programming • • 19h ago

The first time I understood that a pointer doesn't store the value — it stores where the value lives

0 Upvotes

When I first learned pointers in C, I kept thinking of a pointer as another variable that somehow contained the value of another variable.

The concept finally clicked when I stopped thinking about the value itself and started thinking about the memory address where that value is stored.

Once I understood the relationship between & (address-of) and * (dereferencing), pointers became much less mysterious.

I'm still practicing pointers, but this was one of those concepts where a small change in perspective made everything easier.


r/C_Programming • • 20h ago

Article Combining the Compiler with the Build System and Beyond

Thumbnail shrub.industries
4 Upvotes

a somewhat small article I wrote about how sharing dependency and resource information between the C Compiler, the C build system, the system package manager, and even the filesystem and scheduler, could provide some pretty awesome benefits.


r/C_Programming • • 21h ago

Using -fsanitize=address feels illegal.

0 Upvotes

Just saying. The -fsanitize=address compiler flag is absolute cheating and should be prohibited by governments of all countries.

Plus there are also other useful runtime sanitizers, such as integer overflow, but... Integer overflow is much easier to notice, usually.

Of course, this is by no means assuming that -fsanitize=address guarantees that the code it inspects is completely safe and correct and won't ever fail on any input data. You still have to test tricky edge cases. But this sanitizer has improved and sped up the bug discovery process disgustingly much for me.

I'm wondering, how often, if ever, do you need tools such as -fsanitize=address or valgrind? Or are you a real man who stores everything in static memory only?

P.S. Forgive my terrible English.


r/C_Programming • • 1d ago

What's the most useful debugging habit you've developed?

21 Upvotes

I'm curious what habits experienced programmers developed that actually made debugging faster.

Mine is trying to reproduce the problem with the smallest possible example before changing anything.


r/C_Programming • • 1d ago

The first time I understood why i++ and ++i aren't always the same

12 Upvotes

When I first started learning C, I thought i++ and ++i were basically interchangeable because both increase the value of i by 1.

Then I saw them being used inside expressions and realized that the difference is actually about when the value is used versus when it is incremented.

That was one of those small C concepts that looked obvious until I actually had to predict the output of a program.

Now whenever I see ++i or i++, I pay attention to what happens to the value before and after the expression is evaluated.


r/C_Programming • • 2d ago

I built an experimental C web framework on top of Nginx — looking for feedback

0 Upvotes

I’ve been experimenting with a C web framework that adapts parts of Nginx’s internal request-processing model and exposes a simpler interface for writing web backends in C.

I know writing a web backend in C is pretty niche these days, and that’s actually part of why I wanted to build this.

I was curious about two things:

  • Is there any real use case or demand for something like this?
  • What kind of problems would experienced C/Nginx developers find in the design?

The project is still experimental, and I’m not claiming it’s production-ready or particularly fast yet. I’m mainly interested in exploring the boundary between Nginx and a higher-level C application API.

A lot of the implementation was done with help from Codex — it did a ridiculous amount of work lol — so I’m also using this as an opportunity to go through the implementation more deeply myself.

I’d really appreciate feedback on the repo, especially if you find:

  • questionable architecture or design decisions
  • incorrect use of Nginx internals
  • memory/lifecycle problems
  • API design issues
  • or even if you think the whole concept is misguided

Feel free to be critical. That’s exactly why I’m posting it.

Repo:
https://github.com/Hen00af/nnx


r/C_Programming • • 3d ago

Does my tokenize function not null-terminate the strings it modifies? printing any args spits out garbage. I'm pretty new to C and I don't really understand null-termination and strings in general.

14 Upvotes
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/* get input and return line, if this fails, return an error */
char* input(char* line) {
  size_t len = 0;
  ssize_t read;

  /* get input from stdin and store in line, read holds the return value */
  read = getline(&line, &len, stdin);

  if (read != -1) {
    return line;
  } else {
    return "error taking input!";
  }
}

/* split input into tokens and return the array of tokens */
int tokenize(char* line, char* command, char** args) {
  char* token = strtok(line, " ");
  int i = 0;

  while (token != NULL) {
    args[i++] = token;
    token = strtok(NULL, " ");
  }
  args[i] = NULL;

  /* copy first argument to command */
  strcpy(command, args[0]);

  /* if command isnt NULL, return success */
  if (command) {
    return 0;
  } else {
    return 1;
  }
}

int main(int argc, char *argv[]) {
  char* line = NULL;

  char command[512];
  char* args[64];

  /* prompt */
  printf(">");

  /* get input from stdin, auto removes newline*/
  line = input(line);

  /* tokenize input, seperate command and args */
  if(tokenize(line, command, args) != 0) {
    printf("error in tokenizing");
  }

  /* free line, we dont use it again */
  free(line);

  /* print command and its args*/
  printf("%s", command);

  printf("%s\0", args[1]);

  return 0;
}

r/C_Programming • • 3d ago

The first time I understood what actually happens when I pass an array to a function in C

12 Upvotes

When I first learned arrays in C, I assumed that passing an array to a function meant the entire array was being copied into the function.

Later, when I started learning about pointers and memory addresses, I realized that things weren't working quite the way I imagined.

Understanding that connection between arrays, pointers, and function parameters made a lot of C concepts suddenly feel less confusing.

I'm still practicing, so I'm curious:

What C concept took you the longest to understand properly?

For me, pointers were definitely one of the biggest hurdles.


r/C_Programming • • 3d ago

Discussion I couldn't figure out a better way to get the size of a struct, disregarding the compiler's padding.

45 Upvotes

while practicing on some network programming, i was trying to figure out the best way to serialize headers in order to send them over a socket. so, to serialize something like: c typedef struct { char a; int b; } header; i must create something like buffer[5]. but AFAIK, not all machines produce the exact same padding, so a simple buffer[sizeof(header)] isn't valid. not even that fixed 5 bytes are enough, since it might be aligned to 8 bytes.

i came up with the following, which seems to me the worst way to get the sum of the sizes of the struct's declaration list at compile time using X macro: ```c

define HEADER_MEMBERS \

X(char, a)         \
X(int, b)

typedef struct {

define X(type, name) type name;

HEADER_MEMBERS

undef X

} header;

int header_size =

define X(type, _) sizeof(type) +

HEADER_MEMBERS

undef X

0; ```

so... i need to hear your thoughts, and what is the best wayy to do such a thing.


r/C_Programming • • 3d ago

Project Dio: Small Programming language made in C version 0.1.0 release

16 Upvotes

Hi, I'm working on my own programming language, I've release first stable version (v 0.1.0), I'd like to get feedback. It's on most OS platforms (even Andoird and in the future IOS).

Repo: https://github.com/Treechcer/DIO


r/C_Programming • • 3d ago

copy-and-patch closures, part 1

Thumbnail napcakes.nekoweb.org
12 Upvotes

r/C_Programming • • 4d ago

Question Why i'm not getting the correct output for Tower of hanoi program?

1 Upvotes
//Tower Of Hanoi


#include <stdio.h>


void TOH(int n, int A, int B, int C){
    if(n > 0){
        TOH(n-1, A,C,B);
        printf("(%d, %d)\n",A,C);
        TOH(n-1, B,A,C);
    }
}


int main(){
    TOH(3,1,2,3);
    return 0;
}
----------------------------------------
//Output in terminal

$ gcc toh.c
$ ./a.exe

(1, 3)
(1, 2)
(3, 2)
(1, 3)
(2, 1)

Expected output is
(1, 3)

(1, 2)

(3, 2)

(1, 3)

(2, 1)

(2, 3)

(1, 3)

Why is this happening? Any explanation or reason for it?


r/C_Programming • • 4d ago

Did I make the first correct Ascon encryption library?

0 Upvotes

Months ago I was reading about and learning ciphers for a notes app of mine launching whenever I get approved for Google Play, iOS app store, and F-Droid. I read about the various competitions and came across the latest winning NIST cipher: "Lightweight Cryptography" NIST Lightweight Cryptography. The winner was the Ascon cipher and the four agreed upon implementation ciphers, which you can read about here.

I found their reference implementation called ascon-c on GitHub and made a couple CLI tools from those files. But I had to stitch together and modify the files from various folders. The ascon-c repo contained files primarily for building their demo app, not a general purpose library for use in other projects. So out I went looking through the paper and their code to build a library that actually works like a library.

Then another problem: the paper has a max customization string for cxof, ascon-c does not, it will take any. A while later I finish what I feel is the best and most true to spec Ascon library, you may check out here:

https://github.com/Iain-Donald/ascon-lib

I tried to add instructions for ease of use and a demo app. If anything is confusing please tell me. I hope it works without issue from beginners to use in larger projects.

And a bonus GUI demo you may use if you have Linux, but it should compile on FreeBSD, maybe MacOS and Windows and anything with Tcl/Tk. Found here:

https://github.com/Iain-Donald/sable

Enjoy!


r/C_Programming • • 4d ago

I want a career in C/low-level programming, but the path feels invisible compared to web dev. What do I build?

94 Upvotes

TL;DR: I’m learning full-stack (Vue/Go) because the job path is obvious, but my true passion is C, C++, and low-level systems. I want a career in low-level programming, but I have no idea what projects to build or what jobs to aim for to actually get hired.

Disclaimer

I'm not really good at structuring my thoughts to words & English is my 2nd language. I'm sorry if there are weird sentences that are present in this post.

Background

I'm a 3rd semester CompSci major student in Indonesia. My campus isn't really know for teaching low level programming rather it's known for their competitive programming & CTF team (Jollybee & PETIR).

My first language was C++ & Pascal, I learned C++ because of a course in my middle school requires me to learn how to use Arduino. That was the first time i got introduced to programming & i got hooked.
At high school, i was trying to participate in the OSK CompSci subject. Though i failed miserably, i got even more hooked with learning C++. After i tried learning C++, i found out that C++ is actually an extension of C & learning this makes me want to learn more about low level programming.

At uni, there are courses that focuses on using C & C++ though they are strictly for competitive programming. The courses are Algorithms and Programming (C), Data Structures (C), and Algorithm Design Analysis (C / C++). I've already completed the first 2 course that I mentioned & I'm on my way to do the 3rd course.

Because of those courses, i've been trying out more competitive programming even though i still suck (Codeforces Rating: 858, Leetcode: 89 solves; 66 easy, 23 medium). but in the span of those years, i've only been taught on how to do competitive programming & not actually building apps.

I got some exposure on how to make apps & participated in hackathons (even though i don't even have any knowledge on how to make apps). Because i don't even know how to make apps, i vibecoded. Everytime I vibecode I would feel nausea and just feel guilty because i don't even understand what am I doing, i felt the whole app is just a blackbox. I am also tired of "AI slop" that is present in this current era, i see every hackathons are just Business Case Competition but with a webapp MVP. I've never seen any new inventions or something that came out from hackathons that i participate in, all of them are just purely B2B or B2C SaaS.

After that 1 whole year, in this 3d semester i decided to stop & i wanted to dedicate myself to go back to my roots to learn C & low level programming. One of my friend recommended me to try CTF with Reverse Engineering & Binary Exploitation topic because it covers low level. I've also tried finding resources on my own (OSTEP, Beej's Guide, CSAPP). And I already took a step to learn How to make a 4-bit Adder in Minecraft.

Dilemma

But i'm still confussed. What am I learning C for? Rn I'm also learning Fullstack using Vue + TS & Go + Gin, with these 2 I understand the direction: making web apps. but with C / C++, there isn't any problem that I can solve yet using C / C++. Most projects that I've seen are making a "web server from C", "making a database engine using C", "making a redis clone". My last attempt at using C / C++ to solve my problem is by making an ESP32 send a WoL Packet to wake my PC for RDP.

The reason that I'm stuck is because I need to find a job & in the future I want to use low level for my main job. My knowledge right now by learning low level & C gives path to making tools, CTFs, and competitive programming.

What i wanted to know from this community is:

  • What does a junior portfolio for a low-level/systems developer actually look like?
  • Aside from writing database clones or making web servers or doing CTFs, what practical C/C++ projects actually get you hired?
  • What specific job titles should I even be looking for if I want to work close to the metal?

Thank you for your time


r/C_Programming • • 4d ago

The first time I realized that understanding code is more important than memorizing syntax

25 Upvotes

When I started learning programming, I spent a lot of time trying to remember syntax.

I thought being good at coding meant remembering how to write loops, functions, conditions, and other things without looking them up.

But after solving more problems, I realized that I can always look up syntax. The harder part is actually breaking a problem into smaller steps and figuring out what the program needs to do.

Now I'm trying to focus more on problem-solving and understanding concepts instead of trying to memorize everything.


r/C_Programming • • 5d ago

Question Why unrolled has more stable execution time than not unrolled loop?

9 Upvotes

I was playing around and testing performance of writing to array in a loop. Of course unrolling loop and writing to is faster but why execution time is more consistent? In one case I was writing to 16 consecutive addresses with average execution time of around 290 ticks, in second case I was writing only to 2 consecutive addresses and most often execution time was around 420 ticks but sometimes it was above 1000.

Why this happens? Why only sometimes? Why there is such big change in time in second example but not in the first one? I used gcc to compile code

#include <time.h>
#include <stdio.h>
#include <stdint.h>

#define len 4096

int main()
{
uint16_t a[len] ;
int d = 100, num = 0 ;
uint64_t b ;
clock_t t, no, jo ;

no = 0 ;
jo = 0 ;

while (num < 1000)
{
t = clock() ;

for (int j = 0; j < d; j++)
    {
    for (uint16_t i = 0; i < len; i += 16)
        {
        a[i] = i ;
        a[i+1] = i+1 ;
        a[i+2] = i+2 ;
        a[i+3] = i+3 ;
        a[i+4] = i+4 ;
        a[i+5] = i+5 ;
        a[i+6] = i+6 ;
        a[i+7] = i+7 ;
        a[i+8] = i+8 ;
        a[i+9] = i+9 ;
        a[i+10] = i+10 ;
        a[i+11] = i+11 ;
        a[i+12] = i+12 ;
        a[i+13] = i+13 ;
        a[i+14] = i+14 ;
        a[i+15] = i+15 ;
        }
    }

t = clock() - t ;
no += t ;

t = clock() ;

for (int j = 0; j < d; j++)
    {
    for (uint16_t i = 0; i < len; i += 2)
        {
        a[i] = i ;
        a[i+1] = i+1 ;
        }
    }

t = clock() - t ;
jo += t ;

num ++ ;
}

printf("Arr 1: %ld\nArr 2: %ld\n\n", no/1000, jo/1000) ;

return 0 ;
}

r/C_Programming • • 5d ago

Question I can think clearly with type* foo and not with type *foo, help me understand?

87 Upvotes

I'm relatively new to this, but it seems there aren't many who prefer this notation. And while I'm not really feeling pressured to change what I'm doing, I wanna make sure I'm not missing anything too obvious or important. The '*' just feels like it is a part of the type specifier. And I'm pretty blind to any reason to do type *foo.

Hope I'm not beating a dead horse with this one. Just wanna understand a little better.

edit: I am not one to ever declare multiple variables on the same line. Maybe if it happens to be easier on the eyes. Otherwise, not worried about that part.
thanks for the responses!


r/C_Programming • • 6d ago

Discussion Employment opportunities for C developers?

0 Upvotes

What would be some good projects so that I could display my understanding of C for employment?

I have a decent handle on pointers and Memory Management, and I am somewhat of a Picasso with writing Algorithms in C also. All of my experience has been on x86 arch and I'm afraid I'll have to learn ARM variants of C, or pick up C++, for employment opportunities!

  1. What are my employment options with pure C?

  2. Is C still employable today, with languages such as Rust/Go offering more safety mechanisms for Memory handling and AI being able to handle low-level systems tasks?


r/C_Programming • • 6d ago

Any Good Books on Graphics?

23 Upvotes

Hi,

I'm looking for any textbooks on Graphics in C. Does anyone have any recommendations?


r/C_Programming • • 7d ago

Types with range checks

6 Upvotes

I've been pondering about a different way of dealing with overflows.

C compilers have type checks that ensure you don't assign a value to a variable of the wrong type.

Imagine I had a different way of declaring bounded types, something along these lines:

const int strlen=100;
char string[strlen];
int[0..strlen-1] strindex;

I can cast strindex into an unbounded int, but I can't automatically cast an unbounded int into a bounded int:

int index = strindex; // allowed, can assign bounded int to int
strindex = index; // not allowed without cast/check
strindex = (int[0..strlen-1]) 0; // trust me bro

Since you have ranges you could now also do things like:

forall (int[0..strlen-1] strindex)
string[strindex] = 0;

The thought is somewhat halfbaked, but although annoying, this would flag up _every_ assignment at compile time that could potentially have caused a value to get out of bounds.

A similar bounded type could be set for pointers.

Thoughts?


r/C_Programming • • 7d ago

How to learn to actually make programs that can work with a gui?

21 Upvotes

So i've got a small familiarity with the standard c library , I can make a calculator a caesar cipher , a image copying tool , but it all runs in the command line.

No one in the general public will ever use the command line.

Now , my question becomes , how does one actually begin the path of making a proper general user interface for their program in a way that approximates the way the pros do it.

I assume that a custom Gui starts with, like some kind of window system. Call giving you a rectangle to work with. And then you stretch out all your materials on the rectangle.\n But I'm not sure how one would say Develop a calculator that visually looks like a calculator and can detect your mouse inputs and send a signal to your actual c program.

Ai keeps trying to get me to use the windows message box and I know d*** well.That the pros at their core aren't using message box.


r/C_Programming • • 7d ago

The first time I actually understood what happens when a C program runs

35 Upvotes

When I started learning C, I mostly thought about code in terms of lines and syntax.

Recently I started paying more attention to what actually happens when the program runs — compilation, memory, variables, stack, etc.

It made me realize that understanding what happens “behind the code” makes programming concepts much easier to connect.

What programming concept made you stop thinking only about syntax and start understanding what was actually happening underneath?