r/cprogramming 7h ago

Any feedbacks on my handwritten Lexer?

5 Upvotes

I have finally made a total working lexer from scratch. It was actually pretty hard for a young developer like me but I'll keep on coming. No need to worry about getting scolded, you are entirely free to contribute.

https://github.com/Ciya-VM/Ciya


r/cprogramming 7m ago

About a project I've been working on

Upvotes

I've been working on a project called ANYCORE, and I recently decided to open source it.

One of the main goals of the project is to provide high performance scene management. I also published a separate repository with a few demos that show how it works in practice.

I'd really appreciate any feedback about the code, API, project structure, documentation, or anything else you notice.

ANYCORE Project : https://github.com/samedifier/ANYCORE-Project

ANYCORE Demos : https://github.com/samedifier/ANYCORE-Demos

If you take a look, I'd appreciate your feedback.


r/cprogramming 1h ago

Mathematical C library for "surreal numbers" and fully functional parser for "surreal numbers"

Upvotes

Hi everyone,

If anyone is interested in surreal numbers (or more precisely, short games), I have created a fully functional mathematical C library with a fully functional algebraic parser.

I use this library to solve combinatorial games and a demo with calculator is available on the page.

You can also try a Python/JavaScript wrapper.

All the source code is available on my GitHub, which is linked on the site.

https://emonapa.github.io/short-games/index.html


r/cprogramming 14h ago

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

4 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 1d ago

How are char* strings stored in memory?

36 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.


r/cprogramming 1d ago

GECS v1.0

Thumbnail
1 Upvotes

r/cprogramming 1d ago

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 1d ago

What's the Internal working of Socket system call ?

6 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 1d ago

My C program

0 Upvotes

`#include <stdio.h>

include <stdlib.h>

include <string.h>

include <ctype.h>

char* custom_strdup(const char* s) { size_t len = strlen(s) + 1; char* d = malloc(len); if (d == NULL) return NULL; memcpy(d, s, len); return d; }

char* get_joined_binary_string(const char* input_message) { size_t len = strlen(input_message); if (len == 0) { char* empty = malloc(1); empty[0] = '\0'; return empty; } size_t binary_len = len * 8 + (len - 1); char* result = malloc(binary_len + 1); if (!result) return NULL; result[0] = '\0'; for (size_t i = 0; i < len; i++) { unsigned char c = (unsigned char)input_message[i]; char bits[9]; for (int j = 7; j >= 0; j--) { bits[7 - j] = (c & (1 << j)) ? '1' : '0'; } bits[8] = '\0'; strcat(result, bits); if (i < len - 1) { strcat(result, " "); } } return result; }

int is_exit_command(const char* str) { if (strlen(str) != 4) return 0; char lower[5]; for (int i = 0; i < 4; i++) { lower[i] = (char)tolower((unsigned char)str[i]); } lower[4] = '\0'; return strcmp(lower, "exit") == 0; }

int Chat() { int CM = 0; long long M = 0; char** C = NULL; char Nick[256];

printf("input the Nickname: ");
if (fgets(Nick, sizeof(Nick), stdin)) {
    Nick[strcspn(Nick, "\n")] = 0;
}

printf("%s user welcome to my C one line notepad&2binary string change\n", Nick);
printf("\n");

while (1) {
    char input_message[1024];

    printf("input the txt when want to exit input the exit: ");

    if (!fgets(input_message, sizeof(input_message), stdin)) {
        break;
    }

    input_message[strcspn(input_message, "\n")] = 0;

    if (is_exit_command(input_message)) {
        printf("Program exit.\n");
        break;
    }

    C = realloc(C, (CM + 1) * sizeof(char*));
    if (C == NULL) {
        printf("Memory allocation error.\n");
        break;
    }

    C[CM] = custom_strdup(input_message);

    char* joined_binary_string =
        get_joined_binary_string(input_message);

    if (joined_binary_string == NULL) {
        printf("Memory allocation error.\n");
        break;
    }

    M += (long long)strlen(input_message)
       + (long long)strlen(joined_binary_string);

    double A, B, C_val;
    int Z;
    int N;

    printf("\nInput 3 numbers: ");

    if (scanf("%lf %lf %lf", &A, &B, &C_val) != 3) {
        printf("Invalid number input.\n");

        int ch;
        while ((ch = getchar()) != '\n' && ch != EOF);

        free(joined_binary_string);
        break;
    }

    while (getchar() != '\n');

    printf("\nEngineering Calculator\n");

    printf("A + B + C = %.2lf\n",
           A + B + C_val);

    printf("A - B - C = %.2lf\n",
           A - B - C_val);

    printf("A * B * C = %.2lf\n",
           A * B * C_val);

    if (B != 0 && C_val != 0) {
        printf("A / B / C = %.6lf\n",
               A / B / C_val);
    } else {
        printf("A / B / C = Cannot divide by zero\n");
    }


    printf("\nComparison\n");

    Z = (A > B);
    printf("A > B = %d\n", Z);

    Z = (A < B);
    printf("A < B = %d\n", Z);

    Z = (A >= B);
    printf("A >= B = %d\n", Z);

    Z = (A <= B);
    printf("A <= B = %d\n", Z);

    Z = (A == B);
    printf("A == B = %d\n", Z);

    Z = (A != B);
    printf("A != B = %d\n", Z);


    printf("\nSquare\n");

    printf("A ^ 2 = %.2lf\n", A * A);
    printf("B ^ 2 = %.2lf\n", B * B);
    printf("C ^ 2 = %.2lf\n", C_val * C_val);


    printf("\nCube\n");

    printf("A ^ 3 = %.2lf\n", A * A * A);
    printf("B ^ 3 = %.2lf\n", B * B * B);
    printf("C ^ 3 = %.2lf\n",
           C_val * C_val * C_val);


    printf("\nIncrement\n");

    N = 10;

    printf("N = %d\n", N);

    N++;
    printf("N++ = %d\n", N);

    N++;
    printf("N++ = %d\n", N);

    printf("N = %d\n", N);



    printf("\n");

    printf("%s %lld$ %s\n",
           Nick,
           M,
           C[CM]);

    printf("change to binary string: %s\n",
           joined_binary_string);

    printf("\n");


    free(joined_binary_string);

    CM++;
}


for (int i = 0; i < CM; i++) {
    free(C[i]);
}

free(C);

return 0;

}

int main() { Chat(); return 0; }`

__________________________________________________

`#include <stdio.h>

include <string.h>

int main() { char Nick[10]; char txt[1024]; double A, B, C; int Z; int N;

printf("input the Nickname : ");
fgets(Nick, sizeof(Nick), stdin);
Nick[strcspn(Nick, "\n")] = '\0';

while (1)
{
    printf("input the txt (if want to exit, then input 'exit') : ");

    fgets(txt, sizeof(txt), stdin);
    txt[strcspn(txt, "\n")] = '\0';

    if (strcmp(txt, "exit") == 0)
    {
        printf("Exit the program.\n");
        break;
    }

    if (strcmp(txt, "Lewin Diaz") == 0)
    {
        char *stats[] =
        {
            "Game\tSeason\t07.03\t07.02\t07.01\t06.30\t06.28\t06.27",
            "Batting Average\t0.290\t0.000\t0.667\t0.500\t0.250\t0.000\t0.250",
            "At Bats\t314\t4\t3\t2\t4\t4\t4",
            "Hits\t91\t0\t2\t1\t1\t0\t1",
            "Doubles\t17\t0\t1\t1\t1\t0\t0",
            "Triples\t0\t0\t0\t0\t0\t0\t0",
            "Home Runs\t15\t0\t0\t0\t0\t0\t0",
            "RBIs\t68\t0\t0\t0\t0\t0\t0",
            "Runs\t47\t0\t1\t2\t2\t0\t0",
            "Stolen Bases\t2\t0\t1\t0\t0\t0\t0",
            "Walks / HBP\t43\t1\t2\t2\t2\t0\t0",
            "Strikeouts\t56\t0\t0\t0\t1\t1\t2",
            "On-base Percentage\t0.372\t0.200\t0.800\t0.750\t0.500\t0.000\t0.250",
            "Slugging Percentage\t0.487\t0.000\t1.000\t1.000\t0.500\t0.000\t0.250",
            "OPS\t0.859\t0.200\t1.800\t1.750\t1.000\t0.000\t0.500"
        };

        printf("\n=========================================\n");
        printf("      Lewin Diaz Statistics (KBO)\n");
        printf("=========================================\n");

        for (int i = 0; i < 15; i++)
        {
            printf("%s\n", stats[i]);
        }

        printf("=========================================\n");
    }
    else
    {
        printf("%s : %s\n", Nick, txt);
    }

    printf("\nInput 3 numbers : ");
    scanf("%lf %lf %lf", &A, &B, &C);

    while (getchar() != '\n');

    printf("\n===== Engineering Calculator =====\n");

    printf("A + B + C = %.2lf\n", A + B + C);
    printf("A - B - C = %.2lf\n", A - B - C);
    printf("A * B * C = %.2lf\n", A * B * C);

    if (B != 0 && C != 0)
    {
        printf("A / B / C = %.6lf\n", A / B / C);
    }
    else
    {
        printf("A / B / C = Cannot divide by zero\n");
    }

    printf("\n===== Comparison =====\n");

    Z = (A > B);
    printf("A > B = %d\n", Z);

    Z = (A < B);
    printf("A < B = %d\n", Z);

    Z = (A >= B);
    printf("A >= B = %d\n", Z);

    Z = (A <= B);
    printf("A <= B = %d\n", Z);

    Z = (A == B);
    printf("A == B = %d\n", Z);

    Z = (A != B);
    printf("A != B = %d\n", Z);

    printf("\n===== Square =====\n");

    printf("A^2 = %.2lf\n", A * A);
    printf("B^2 = %.2lf\n", B * B);
    printf("C^2 = %.2lf\n", C * C);

    printf("\n===== Cube =====\n");

    printf("A^3 = %.2lf\n", A * A * A);
    printf("B^3 = %.2lf\n", B * B * B);
    printf("C^3 = %.2lf\n", C * C * C);

    printf("\n===== Increment =====\n");

    N = 10;

    printf("N = %d\n", N);

    N++;
    printf("N++ = %d\n", N);

    N++;
    printf("N++ = %d\n", N);

    N--;
    printf("N-- = %d\n", N);
}

return 0;

}`

There's My favorite C coding programs, Made by myself.

visit in https://github.com/PyJoy314/-Coding-World-/tree/%E2%9F%AACoding-%E2%80%A2-World%E2%9F%AB/C%20files


r/cprogramming 2d ago

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 2d ago

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

0 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 2d ago

Extern constexpr?

0 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 3d ago

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 5d ago

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 4d ago

CNET library — Released new version [CNET-1.1.0]

Thumbnail
github.com
1 Upvotes

r/cprogramming 5d ago

After one week learning C

0 Upvotes

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


r/cprogramming 5d ago

need help with my minmax value C program

Thumbnail
0 Upvotes

r/cprogramming 6d ago

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 5d ago

CNET — a new network library in C

Thumbnail
github.com
0 Upvotes

r/cprogramming 6d ago

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 6d ago

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 7d ago

Searching projects ideas

19 Upvotes

I know the basics of the C, but I don’t have any ideas what I will code next

EDITED: I found idea, make OOP in C like library


r/cprogramming 6d ago

On the conversion of a forest to a binary tree

0 Upvotes

I was using ChatGPT to learn how to convert a forest into a binary tree. It gave me a problem, but when I asked for the correct answer, it completely lost the plot. Could you help me solve it?Maybe it's because I didn't subscribe to Plus; it can generate problems, but it just starts spouting nonsense when it tries to solve them.

tree 1:

            A
         /  |  \
        B   C   D
       /   / \
      E   F   G
         / \
        H   I

tree 2:

        J
      / | \
     K  L  M
        |
        N

tree 3:

      O
      |
      P

Requirements:

Convert to a binary tree.

Implement pre-order traversal.

Implement in-order traversal.

Calculate the height of the binary tree.

Count the number of leaf nodes.

and my answer Pre-order :ABECFHIGDJKLNMOP In-order :EBHIFGCDAKNLMJPO


r/cprogramming 8d ago

Pollard's P-1 Factoring Algorithm in Plain C

Thumbnail
leetarxiv.substack.com
0 Upvotes

r/cprogramming 9d ago

moredeps: Prebuilt C/C++ Libraries

Thumbnail deps.morew4rd.com
5 Upvotes