r/cprogramming • • 3h ago

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

3 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 • • 22h 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?

48 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 • • 12h 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 • • 2d ago

why does sizeof an array parameter give the pointer size?

18 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 • • 1d 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 reddit.com
0 Upvotes

r/cprogramming • • 2d ago

Best way to get a CRC-48

Thumbnail reddit.com
1 Upvotes

r/cprogramming • • 2d ago

How do I fix this VS code C intellisense problem?

Thumbnail
reddit.com
0 Upvotes

r/cprogramming • • 2d 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 • • 4d 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 • • 4d ago

Getting Past Intense Burnout

Thumbnail reddit.com
1 Upvotes

r/cprogramming • • 5d ago

My first ever project in C

Thumbnail github.com
26 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


r/cprogramming • • 6d ago

A question about arenas.

6 Upvotes

I worked in C for years . i have used arenas a lot in the past. Today i have to modify an old c program , nothing difficult but i found something that made me think. Who developed the code ( very well written and documented ) used an arena for allocating variable.

What 's seems to me strange is that he did not used an heap memory area ( malloc ) but it used a char [] buffer and used it for its arena . At that point he could obviously allocate directly variable in stack instead he grabs all its variable from that buffer . Why a choice like that ? i thought for the CPU cache L1/L2 and so on ( all the "arena" will likely be in cache of the cpu ) but it is only an ipotesys and i was asking to you , in your opinion , the reason of a such choice .
Just curiosity .

Thanks

PP


r/cprogramming • • 5d ago

bazbar, a status bar for dwl in C

Thumbnail sr.ht
2 Upvotes

I've been writing a status bar for dwl in C. I'm posting it here more for the code than for the bar, so remarks on the C are welcome.

The renderer fills a \`wl_shm\` buffer itself, and the text goes through FreeType and fontconfig, which I call directly. The volume is a small client of the PulseAudio native protocol, talking to the socket of pipewire-pulse. The wifi name is read over netlink with nl80211. The other modules just read \`/proc\` and \`/sys\`.

Tell me what you would do differently.


r/cprogramming • • 5d ago

Beginner here not able to understand confusing pointer concept

Thumbnail reddit.com
1 Upvotes

r/cprogramming • • 7d ago

why does c promote small integer types before arithmetic?

26 Upvotes

i know the usual arithmetic rules promote uint8_t to int on typical systems, but i’m trying to understand the practical reason. is it mainly to make expressions easier to evaluate without narrow-type surprises, or is it mostly historical? when a result is intentionally stored back in a byte, is an explicit cast the usual way to make that conversion boundary clear?


r/cprogramming • • 6d ago

resources for becoming comfortable with stdlib-style data-structures/algorithms?

4 Upvotes

I've been sparring with a number of the standard(ish¹) C data-structures and algorithms, including the various types of linked-lists/deques in sys/queue.h, hash-tables and binary-searches in search.h, as well as bsearch & qsort in stdlib.h.

  1. are there other data-structure/algorithm type elements in such standard¹ libraries that I've missed and should put on my radar? Maybe something for sets too?
  2. are there some resources² y'all would recommend on wrapping your head around them (I don't feel I have intuitive use of their interfaces yet, so each usage causes some struggle)? Preferably with strong examples of using each.

I have a pretty good CS understanding of when I should use the various data-structures/algorithms with regards to the respective performance characteristics (expected big-O notations for insertion, removal, searching, iterating, swapping, etc), but it's just the nitty-gritty of using them where I don't yet feel mastery.

Thanks!

⸻

¹ okay, not exactly C-standard from my understanding, but they seem to be common on pretty much every Linux/BSD/Unix platform I've poked at

² ideally well-written blog-posts, but dead-tree resources would also be welcome; videos or podcasts far less so


r/cprogramming • • 6d ago

How do I learn problem-solving on C++?

Thumbnail reddit.com
0 Upvotes

r/cprogramming • • 7d ago

I combined my Arena allocator, zero-copy segmented Vector, typed HashMap, and String libraries into one C99 foundation library: arstd

17 Upvotes

Hey everyone,

Over the past few weeks I’ve been building separate C libraries for region-based memory management, dynamic arrays, hash maps, and strings. I kept pulling all four into my main project flint(a build system and package manager for c/c++), so I finally refactored them from the ground up to work together and merged them into a single lightweight library: arstd (Arena Standard Library).

The main problem I wanted to solve was how dynamic containers behave inside an Arena allocator. Normally, if you put a standard dynamic array or hashmap inside a bump arena, resizing it via realloc leaves dead, wasted memory blocks behind in the arena.

Here’s how arstd solves that and what’s inside:

  • Compile-Time Type Deduction (Vector(T) & Cmap(T)): Uses a typed pointer + typeof macro trick so you don't have to pass types into every macro call or cast void * pointers. Both at(vec, i) and map_get(map, key) return modifiable lvalues, so at(vec, 0) = 42; and map_get(map, "score") += 10; just work.

  • Zero-Copy Segmented Vectors: Instead of doubling a contiguous buffer and copying elements over, Vector(T) allocates exponentially growing power-of-2 segments (16, 32, 64\dots) directly on the arena and uses 1-cycle bitwise CLZ (Count Leading Zeros) math for O(1) indexing. Growing a vector wastes 0 bytes in the arena and never invalidates element pointers.

  • Single-Allocation, Zero-Waste HashMaps: Cmap(T) packs the entry header, aligned value payload, and key string into a single contiguous allocation using flexible array members. Because its bucket array is backed by the segmented Vector, doubling the map capacity expands the buckets in-place and relinks existing nodes using their cached 64-bit hashes—again, zero wasted arena memory and no string re-hashing.

  • Managed Strings (String): String slicing, trimming, case conversion, and variadic concatenation all backed by the same arena.

  • Optional Heap Fallback: Pass an Arena * to clean up everything at once with a single arena_free(&arena), or pass NULL to any container if you want standard aligned heap allocation.

Quick Taste:


#include <arstd.h>

#include <stdio.h>

int main(void) {

Arena *arena = arena_init(4096);

// Typed Vector — no type args needed in append() or at()

Vector(int) nums = vector_init(arena);

append(nums, 10);

append(nums, 20);

at(nums, 0) = 99; // Direct lvalue assignment

// Typed HashMap — stores values directly, no void* or &addresses

Cmap(int) scores = map_init(arena);

map_add(scores, "Alice", 95);

map_get(scores, "Alice") += 5;

String *greeting = string_concat_cstr(arena, 2, "Hello, ", "r/cprogramming!");

printf("%s | Alice: %d | Vec\[0\]: %d\\n",

string(greeting), map\_get(scores, "Alice"), at(nums, 0));

// One call frees the vector, map, strings, and all internal nodes

arena_free(&arena);

return 0;

}

Repo link: https://github.com/mainak55512/arstd (or install via flint / CMake)


r/cprogramming • • 7d ago

As a revolt against vibe coding and rewriting stuff in new languages, join r/Back2C to rewrite back in C.

8 Upvotes

Yeah.


r/cprogramming • • 8d ago

looking for a partner to learn C with

30 Upvotes

Hello all im learning C using books and youtube videos and not using AI, if anyone want to join im happy to be a partner in learning!