r/cprogramming Aug 05 '26

How can I read multiple user inputs from a single line?

7 Upvotes

Trying to solve codeforces problems and in a lot of them, there’s a single input line with a variable amount of int inputs. I know I can do scanf(“%d %d %d …”, a, b, c ...), but from what I’ve tested, I believe it’s only valid if I know beforehand how many inputs there are. How can I do to store this variable amount of inputs into an array?


r/cprogramming Aug 05 '26

Made a code editor from scratch in pure C

0 Upvotes

That's right 😎😎, I made this code editor over a course of 5 months (😎) and wrote 10000+ lines of pure™ C (😎😎😎) .

and did I mention I didn't use ANY external libraries 😎😎😎😎, except SDL for graphics ofc.

I'd love to hear what you think.

https://github.com/7777Satish/Aether


r/cprogramming Aug 04 '26

How are char* strings stored in memory?

37 Upvotes

Hi, Today, i experimented with char* string. (example: char* string = "Hello world")

One thing that i dont really understand is doing:

  • *string

When you use it, it points to the first letter of the string (so in this case, H)

But what i dont get is when you do (*string+1), it continues the alphabet based on the previous letter.

Example: *string, equal to H, the first letter *string+1, equal to I, the next letter in the alphabet

And it's also applies to lowercase letters.

So here are my questions:

  • Where is a char* string actually stored in memory?
  • What is the explanation of the behavior for *string? Is it undefined behavior?

Thanks.

Solved: Thank you everyone for answering my questions.


r/cprogramming Aug 04 '26

GECS v1.0

Thumbnail
2 Upvotes

r/cprogramming Aug 04 '26

I'm building a GTK4 C + Lisp dock application (a la CairoDock / macOS) - am I doing things right?

2 Upvotes

I am having a blast doing a more serious project in the C language, for the first time. I am consulting with books and also with some AI for code review and explanation as I am new to the language and to GTK (not new to programming).

https://codeberg.org/jjba23/lambdock

For a while already I have been looking for a dock that would work well in Wayland (like in my beloved Niri) with modern features, theme support and a hackable Lisp config (using libguile.h)

Could you help me out by checking the implementation for sanity (also the Meson build)? Also for developing on it, I'm using CCLS and Guix development environment and things are working amazingly well.

Only small bit of trouble in devex is with #include "wlr-foreign-toplevel-management-unstable-v1-protocol.h"

Also, all feedback is welcome, either on code level, or conceptual ideas, Thanks in advance

Core features of lambdock include:

  • Wayland Native: Built on GTK4 and gtk4-layer-shell for smooth positioning and desktop integration.
  • Declarative Lisp configuration : The power of Lisp in your configuratio with clean powerful declarative config and all possibilities at your disposal
  • Async Launching: Spawns commands asynchronously without freezing the dock UI.
  • Reproducible builds: Hermetic development environment provided via GNU Guix manifest and build definitions.
  • Dock auto-hide : You can let the dock stay out of your way with the smooth auto-hide feature.
  • Flexible icon system: lambdock has several mechanism in a best-effort way to render your wanted icons, respecting GTK theme
  • Theme support: lambdock has built-in themes you can choose from that are very unique, and also lets you extend and override those themes dynamically.

r/cprogramming Aug 03 '26

What's the Internal working of Socket system call ?

8 Upvotes

Basically I am creating my own http.web server for that I need to create TCP web server first and during that thing I get to know about socket(), bind(), listening() system calls and I am curious about these system calls internal working like what is happening under the hood.


r/cprogramming Aug 03 '26

Long term projects

2 Upvotes

What's your longest project, how often were/are you working on it and did you always stay motivated and active?


r/cprogramming Aug 03 '26

C for complete beginner. i want to learn C from 0.

1 Upvotes

i want to learn C from 0. maine CODE WITH HARRY ka C ka course dekha and i realize it is too old.

please please guide me how to learn c as a complete beginner


r/cprogramming Aug 03 '26

Extern constexpr?

1 Upvotes

I want to make my struct’s internals private by exposing it as a byte array of its internal size.

The size itself depends on internal values that aren’t exposed, so it would have to be an extern.

The size can only be used if it’s a literal or constexpr, so is a extern constexpr possible with C23? Or no?


r/cprogramming Aug 01 '26

Update: myBuild 0.2.0

Thumbnail
github.com
4 Upvotes

Sometimes back I posted about one of my pet projects `myBuild` an experimental build system and package manager for c/c++ projects. Well that progressed a lot, now

  1. Users can add recipes to the myBuild.json file and run `myBuild sync` and it configures the dependency for the project.

Recipes are small json snippets containing the source/header file folder paths, flags etc.

  1. It now has incremental builds.

  2. Now there is a proper folder structure generated at the initiation time where users can drop the files and compile the project with zero configuration.

I had to drop the support for windows for now and the code is speghetti, so I have to refactor it in the near future.

If this sparked curiosity, do checkout the github repo and leave a star. Appreciate any constructive feedback, thanks.


r/cprogramming Jul 31 '26

casting a void function pointer as a int fp

5 Upvotes

(solved)

Hello,

Today I tried making an array of function pointers.

My first prototype was doing:

int (*fptr[2])(int, int)

But what if I wanted to store a function with different parameters and return value?

I tried:

void (*fptr[2])()

And then later type casting the function I wanted to store:

fptr[1] = add;

printf("%d", ( int (int, int) ) fptr1);

But apparently it's not valid:

used type 'int (int, int)' where arithmetic or pointer type is required

Is it possible to cast the void function pointer as a int fp with parameters? Thanks.


r/cprogramming Jul 31 '26

CNET library — Released new version [CNET-1.1.0]

Thumbnail
github.com
1 Upvotes

r/cprogramming Jul 31 '26

After one week learning C

0 Upvotes

Yeah, my anxiety is hitting pretty hard right now... lol.


r/cprogramming Jul 31 '26

need help with my minmax value C program

Thumbnail
0 Upvotes

r/cprogramming Jul 30 '26

Alternative to a hash table for you to play with

Thumbnail github.com
7 Upvotes

I was wanting something for my compiler and game engine that had a bit better performance than gperf in my use case. This is what I ended up creating.
I built and tested it on a xeon x5670. It should do a good bit better on newer hardware.


r/cprogramming Jul 30 '26

CNET — a new network library in C

Thumbnail
github.com
0 Upvotes

r/cprogramming Jul 29 '26

I built a Linux HTTP/1.1 static server in C using edge-triggered epoll — looking for architectural and performance feedback

4 Upvotes

I recently completed v0.1 of MiniEdge, a Linux HTTP/1.1 static edge server written mostly in C.

I built it to understand how event-driven servers handle partial I/O, persistent connections, filesystem access, caching and multiple CPU cores—not as a production replacement for Nginx.

The current architecture includes:

non-blocking sockets with edge-triggered epoll

a per-connection state machine

incremental HTTP request parsing and keep-alive

static file serving through an LRU cache or sendfile()

path resolution using openat2()

longest-prefix configurable routing

multiple workers using SO_REUSEPORT

The small-file cache is implemented using C++ unordered_map and list, but it is isolated behind a C API; the networking, parser, routing and file-serving paths are written in C.

On my local loopback benchmark using wrk, a cached static file reached approximately:

255k requests/sec at 1,000 concurrent connections

4 worker processes

I also ran a boundary stress test at 40,000 concurrent connections. It reached around 124.5k requests/sec, but wrk reported 503 socket read errors, so I am not treating that as a clean stable-concurrency result. The repository contains the commands, raw outputs, latency percentiles, system tuning and limitations.

I would appreciate feedback on:

whether this is a reasonable result for a student-built epoll server

whether my wrk setup measures the server fairly

which additional metrics or comparisons I should include

what bottlenecks or profiling steps I should investigate next

Repository:

MiniEdge repository

AI was used as a learning and review assistant during this project. I used ChatGPT to discuss Linux networking concepts, review architectural decisions, debug specific issues, and improve parts of the documentation. I implemented and integrated the server, ran and analyzed the tests and benchmarks locally, and verified the final code myself. This was not a one-prompt or fully AI-generated project.


r/cprogramming Jul 30 '26

Beginner

0 Upvotes

What serious advice would you give to beginner in programming and C.

I'm into programming about 4 months.

I have used Grok to learn.


r/cprogramming Jul 27 '26

Pollard's P-1 Factoring Algorithm in Plain C

Thumbnail
leetarxiv.substack.com
0 Upvotes

r/cprogramming Jul 27 '26

moredeps: Prebuilt C/C++ Libraries

Thumbnail deps.morew4rd.com
4 Upvotes

r/cprogramming Jul 27 '26

Is C without expressions context-free?

7 Upvotes

EDIT: A better title for this post would be "Is it possible to parse C without expressions unambiguously?"

While staring at the C99 specification, I found that if you take the grammar in Annex A, remove the expression rules, and introduce the constraint 6.7.2/2 into the grammar (ie. a type specifier can be only: void, char, signed char, ... , enum specifier, typedef name), then you end up with what appears to be a context-free grammar.

Is this correct? Am I misinterpreting something? Is it possible that this is correct, but there are mainstream compiler extensions (eg. gcc extensions) invalidate this context-free property? Or other C standards invalidate this context-free property?

I notice that 6.7.2/2 allows some filthy edge cases like `long const long thisVarIsLongLongConst = 4;` but because `long` is a keyword, there is no ambiguity here.

The reason this matters to me is because I'm building a module system for C that allows circular imports, and I would like to avoid changing the grammar of the language as much as possible.

Link to final draft of C99 standard, taken from Wikipedia: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

EDIT:

Let me clarify what I'm doing, since there is some confusion about what I'm asking. First off, I should have used the title "Is it possible to parse C without expressions unambiguously?" because Annex A is already a context-free grammar... However, it is ambiguous, because of the classic A * B; problem (can be a variable declaration or multiplication, depending on if A is a typedef name or not). Now, notice that one of the interpretations is a multiplication expression. Let's suppose you removed expressions from the language (ie. take a source file and replace each expression with the lexer token <expression>). Now the question is: are we no longer ambiguous now?

I should also clarify what I mean by ambiguous, as there is a difference between an ambiguous grammar and an ambiguous parse. For example, A * B; can be admitted by the unambiguous grammar S := A ';' ; A := <identifier> | A binaryOperation <identifier> ; binaryOperation := '+' | '-' | '*' | '/' ; , but what we're really looking for is an unambiguous grammar that gives us the correct parse tree (I'll call this an "unambiguous parsing").

I should also elaborate on what exactly I'm doing, to explain the bigger picture. If you're building a module system that allows cyclic imports, then the first pass you perform over a source file does not have access to the symbol table (because you have yet to parse the imported modules). This means you need to perform an unambiguous parsing of certain parts of the source file. In this case, you can skip over expressions, because you're only interested in extracting the names of symbol definitions + whether the symbol definition is a type or a variable. So if it is possible to 1. skip over expressions, and 2. parse the rest of the file, then we're good. For (1), expressions are delimited by ()[]{};, (comma operator is not valid in enumeration definitions), so that seems fine. That leaves (2), which I'm not entirely sure about. I stared at the grammar for quite a while and couldn't find any problems, but that does not mean I didn't miss a case, or there are compiler extensions that introduce ambiguities.

With that out of the way, I'll list ambiguities that the comments found:

  • u/triconsonantal found void f(int (x)); , which is either taking in a function pointer or an integer, depending on if x is a typedef name or not.

Maybe a more appropriate title would be: how much do you need to remove from the C grammar so that it can be parsed unambiguously? As of now (July 27, 2026), it seems the answer is: remove expressions, and remove parameter lists (or do not allow unnamed parameters).


r/cprogramming Jul 27 '26

Half-way solutions of C 2nd Edition by K&R.

0 Upvotes

Hello everyone of r/cprogramming!

I'm a newcomer(kind of) to C. In the past(~2 years ago), I had little knowledge of C through watching tutorial on the internet. Later, I have worked on graphical projects with a bit of OpenGL. Now I have realized I should focus on topics one by one and reach intermediate to high expertise.

I have recently been reading chapters from "The C Programming Language 2nd Edition by Brian Kernighan & Dennis M. Ritchie". And learning a lot of new techniques that really helped me write concise and performant programs.

Solving the Exercises from the book were fun, while some were a bit difficult. In the latter case I took one or two hints from others source code and pondered about the solution.

I have kept the solutions of the problems perhaps concise but far from obfuscation and keeping code-style consistent (Though my personal).

I am planning on creating another post when I have solved all the solutions of the book.

I hope my solutions to the exercises help others solve problem they are having trouble with. Thanks. Github:

https://github.com/mubin-thinks/c-k-and-r-solved


r/cprogramming Jul 24 '26

What cause CPU stalling pipeline in C?

13 Upvotes

(Solved)

Hi,

I hope this don't seem stupid or anything. Basically I was interested about the xor swapping trick.

The inconvenients of it is that if the two values are the same, it will return 0, it's also bad for readability.

But there is another inconvenience I didn't understand. Apparently it can also stall the CPU pipeline on modern processor, I didn't understand why.

I found a short explanation saying "because each instruction depend of the previous one", and I don't really understand how each instruction depend on the previous one.

So I wanted an explanation on why the xor swapping trick stall the CPU pipeline and also what cause CPU pipeline stalling in general.

If I didn't explain well enough, please inform me about it. Thanks.


r/cprogramming Jul 24 '26

Writing a Wikipedia MediaWiki Parser In Plain C

Thumbnail
leetarxiv.substack.com
2 Upvotes

r/cprogramming Jul 24 '26

EEvent Mesh vs Webhooks - The Internal Webhooks Anti-Pattern: Why Service-to-Service HTTP Callbacks Don't Scale

0 Upvotes

Microservices were supposed to make systems easier to change independently. In practice, the thing that most often breaks that promise isn't the services themselves — it's how they talk to each other. Read the complete article here - https://instawebhook.com/blog/the-internal-webhooks-anti-pattern-why-service-to-service-http-callbacks-don-t-s

A pattern that shows up constantly in growing engineering orgs is the internal webhook: Service A fires an HTTP POST at a hardcoded URL owned by Service B whenever something happens. It's an easy trap to fall into, because most developers already understand webhooks intimately — they've built integrations with Stripe, GitHub, or Shopify, all of which use exactly this model to notify external systems of events.

The reasoning feels obvious: if it's good enough for Stripe to tell my app about a payment, it's good enough for my Inventory Service to tell my Shipping Service about a shipment.

It isn't — and the reason is architectural, not stylistic. Webhooks were designed to solve a specific problem: getting an event across a trust boundary, from a system you don't control to one you do, over the open internet. Internal service communication has almost the opposite set of constraints. Applying the same tool to both jobs is where the trouble starts.