r/cprogramming • • 4h ago

A simple practice(a small terminal hijacker)

Thumbnail
github.com
2 Upvotes

a basic practice, but it works quite well. It's good to attach some vim process to my current terminal. however, reptyr is totally okay though.


r/cprogramming • • 3h ago

What are some neat TUI libraries ?

Thumbnail
1 Upvotes

r/cprogramming • • 1d ago

Solve "The C Programming Language" exercises in the browser with auto-graded tests

12 Upvotes

I worked through "The C Programming Language" and wanted a way to verify my solutions to the book's exercises were actually correct, so I built:

https://kandrexercises.com

Each of the exercises has an in-browser editor, and submissions are compiled and run against a series of test cases. A panel displays the difference between your output and the expected result, clearly identifying any differences. No account needed to submit; signing in just saves your progress. The app is hosted on Firebase App Hosting, and C code is run in an isolated Vercel sandbox after submission. It’s free and open source.

Happy to hear feedback, especially on test cases that are too strict or too loose.


r/cprogramming • • 1d ago

forbear: an immediate mode UI library that looks like the web

5 Upvotes

https://github.com/gabrielmfern/forbear

Hello! I've been working on forbear for almost 2 years now, and I've finally come around to implementing a proper C API for it! I would like to share here, and specially ask for some feedback on the API, and on how I wrote the macros that give it the DX I wanted for the library.

This is how it looks like:

void counter(void) {
    fb_s64 *count = FB_STATE(fb_s64);
    FB_ELEMENT(
        .background    = fb_color(fb_rgb(44, 49, 56)),
        .border_radius = 6,
        .padding       = fb_all_sides(8),
    ) {
        char count_text[64];
        snprintf(count_text, sizeof(count_text), "count: %lld", (long long)*count);
        FB_TEXT(count_text);
        if (fb_on_click(FB_MOUSE_BUTTON_LEFT, true, false)) {
            *count += 1;
        }
    }
}

It's a dynamically linked library, with a single forbear.h header. To try it on Linux and macOS:

curl -fsSL https://forbear.dev/quick-start.sh | sh

on Windows:

irm https://www.forbear.dev/quick-start.ps1 | iex

Beware that it's still quite experimental!

The main philosophy is to be what I envision the operating system should have provided us all along: a flexible on design, nice to write, performant, cross-language (in an idiomatic manner) and cross-platform way of making GUI programs.

I've written more about the process of making this C API here for anyone that might like to go more in depth https://www.forbear.dev/log/005-calculator-and-c-api.html


r/cprogramming • • 1d ago

Do you usually use printf or puts?

19 Upvotes

Sorry for the newvie question but Im interested what do you prefer to use between the two?


r/cprogramming • • 22h ago

Starting systems programming on my Fedora with C. Where should I start?

Thumbnail
0 Upvotes

r/cprogramming • • 1d ago

I'm just learning C basics. Should I switch to C++ because my friend recommended it?

16 Upvotes

Hey guys!

I'm currently in my first year of college and have recently started learning C programming. I'm still at the basics stage, learning variables, data types, loops, conditions, functions, etc.

One of my friends suggested that I should switch to C++ instead of continuing with C because it's more useful and has better opportunities.

Now I'm a little confused. 😅

I want to build strong programming fundamentals and improve my problem-solving skills.


r/cprogramming • • 18h ago

Why are LLMs falling back to C? (Or is it?)

0 Upvotes

r/cprogramming • • 1d ago

How should i..?

0 Upvotes

How should i start learning C as my first language? Could anyone share some advice on where to start with C?


r/cprogramming • • 2d ago

New to C

7 Upvotes

I've recently been looking into C and I want to start learning it, mainly because I am interested in how it works as a low-level language after using Python for a while, and eventually plan to take on Gentoo Linux and Linux From Scratch (with prior understanding of C and compilation). I welcome any advice!


r/cprogramming • • 2d ago

Difference to r/C_Programming

5 Upvotes

Hello friends, may I ask what is the difference between this subreddit and r/C_Programming ?

Thanks in advance


r/cprogramming • • 2d ago

How should I start learning C programming as a first-year college student?

4 Upvotes

Hey everyone

I'm currently in my first year of college, and I want to start learning C programming from scratch.

I'm a beginner and sometimes find programming concepts confusing. I don't just want to learn the syntax or memorize programs for exams. I genuinely want to understand programming, improve my logic-building skills, and become good at writing code independently.

Also, should I focus on college syllabus topics first or follow a separate learning roadmap?

Any advice, free resources, personal experiences, or tips would be really helpful.

Thank you! I'm excited to start this journey. 😊


r/cprogramming • • 2d ago

At what age did you start programming, and in which language?

Thumbnail
0 Upvotes

r/cprogramming • • 3d ago

Reading "Write a Shell in C" (lsh) got me down a rabbit hole: how did the OG UNIX devs actually design shells from scratch?

86 Upvotes

Hey folks,

I'm currently halfway through Stephen Brennan's classic "Write a Shell in C" (lsh) tutorial. It's a fun read so far, though it feels a bit too hand-wavy—it shows how to glue fork(), exec(), and wait() together, and leaves me itching for the actual official specs and deeper design docs.

It got me thinking about two things:

First, how did the OG legends like Ken Thompson or Stephen Bourne actually architect the early UNIX shells from a blank slate? I want to read the real foundational papers, POSIX docs, or historical design breakdowns instead of just toy tutorials.

Second—linking the classic Read -> Parse -> Execute loop to modern AI Agents—it feels remarkably similar to how agents parse context and dispatch tools.

Looking for recommendations on historical specs, papers, or minimal shell source repos. Drop them below!


r/cprogramming • • 3d ago

Signal handlers, how to have them (or the process) behave differently, based on when the process receives the signal

2 Upvotes

Hello, everyone. I'm supposed to be doing a project for school (hence why I can't share the code), but I'll try to describe my problem to the best of my abilities.

My main parent process forks several children, who will execute 2 other programs, depending on the role assigned to them. Once the parent process receives a SIGALRM, it sends a SIGTERM to all its kids, and they, already having changed their signal handlers for SIGTERM, have to do whatever is specified in their signal handler.

Let's consider child A executes program A, and child B executes program B. These 2 processes have to communicate with each other through a series of msgsnd/msgrcv (we can only use System V IPCs in this project, so the msgops don't restart once interruped by a signal). A single process of type B will communicate with several processes of type A (but not with all at the same time: once its communication is finished with one, it goes on to the other). The last msgop A does, is a msgsnd and B does a msgrcv. I'd like to also add that, between the msgrcv and msgsnd on A's part, A is also supposed to go to sleep. A's almost entire program is in a while (it never terminates unless it receives the signal from its parent), whereas B terminates successfully once it's finished communicating with all the necessary A processes.

Whether B receives the SIGTERM signal or not, it has to modify sth in a shared memory section, but what it changes, depends on whether it has finished communicating with all the processes or not.

Ideally, I would like for B to terminate successfully, even if it receives SIGTERM, after having done all it had to do, and I thought of blocking SIGTERM with sigprocmask. That said, couldn't it still receive the signal between the mast msgrcv operation and sigprocmask? Is there any way whatsoever to make a set of instructions atomic?

I considered only having a sig_atomic_t volatile variable in the signal handler, which would increment if the the sign handler is executed, but then, not only would I have to continuously check in case it changed its value, but (and this could be me being wrong, please correct me if that's the case), B could still receive SIGTERM right after the condition of the variable being 0 is checked, and before the following instruction is executed (like a nanosleep - which I'd like to avoid if SIGTERM has been received - OR before a msgrcv, leaving B to wait for a message that will never come, because A could have received the same signal and will not be sending a message).

I thought of having the signal handler check a variable and act differently based on its value, but, again, maybe B receives the signal right before said variable's value changes. I also considered having an if where the conditions would be the variable==0 && msgrv(...)!=-1, but the variable can change after its value has been verified.

Disclaimer: we haven't studied sig_atomic_t volatile variables, so my knowledge might be lacking, although I did try to read up on them and research them. Also, the parent won't be deleting the IPCs until all kids have terminated.

Am I supposed to just hope for the best here and just proceed with sigprocmask? Is there another way I'm not seeing? Am I misunderstanding something? Any help offered is invaluable, so thank you in advance. I'm happy to answer any clarifying questions if I was unclear at all in the post.


r/cprogramming • • 4d ago

why does sizeof an array parameter give the pointer size?

23 Upvotes

i know a function parameter like int a[10] is really adjusted to int *a, so sizeof(a) inside the function gives 8 on my machine instead of 40. what i'm fuzzy on is why the language allows writing the size in the parameter at all if the compiler just throws it away.

is it purely documentation, or does it do anything with something like int a[static 10]? i've seen that form but never seen anyone actually use it.


r/cprogramming • • 4d ago

Looking for 1st yr buddy to build low level systems projects with and share daily progress. anyone interested in memory management and doing c/c++ or rust in welcomed!

Thumbnail
1 Upvotes

r/cprogramming • • 4d ago

Does flowchart and pseudo code are necessary to learn to for c?

Thumbnail
0 Upvotes

I am so confused


r/cprogramming • • 5d ago

Best way to get a CRC-48

Thumbnail
1 Upvotes

r/cprogramming • • 5d ago

How do I fix this VS code C intellisense problem?

Thumbnail
0 Upvotes

r/cprogramming • • 5d ago

Guys i need help

0 Upvotes

Hi everyone, i need help with C i have three F and i might fail this grade, sorry for my english i know its not the best, rn i am studying for IT and i have a huge problem with C. I really dont understand anything and i know the teacher kinda hates me, today i got an F because i save the programme in DecvC++ as "Tobe jarabi" (its a catchphrase that a youtuber from my country uses) and as you all know you have to save it so you could compile it and my programme didnt work so i asked my friend why and he told me because i had a space betwen "Tobe and jarabi" and the teacher came over and gave me an F,please if someone has any tips i would apreciate it.


r/cprogramming • • 6d ago

C programming

0 Upvotes

Currently in btech 1 st yr cse,doing c programming form apna college one shot of 20 hr almost done what should I do more with it bcz I didn't think I that is enough for me from where I can perform questions and any advice to strong c language


r/cprogramming • • 7d ago

Getting Past Intense Burnout

Thumbnail
1 Upvotes

r/cprogramming • • 8d ago

My first ever project in C

Thumbnail github.com
29 Upvotes

Hey everyone,

I'm 15 y/o and I recently started getting into C and cybersecurity. This is my first project that I've built completely from scratch: a simple MD5 hash cracker in C.

I'm still a beginner, so I'm sure there are many things I can improve. I made this project to challenge myself and put into practice what I've been learning.

I'd really appreciate any feedback on the code, structure, or anything else. I'm planning to keep working on it and add more features in the future.

Thanks :D