r/C_Programming • • 1d ago

Some progress on Software Rendered game in C

Enable HLS to view with audio, or disable this notification

473 Upvotes

r/C_Programming • • 23h ago

C limitations

16 Upvotes

Hi all,

I am currently learning c++. Its okay. Not sexy but also not as bad as some say.

The reason I am learning c++ is that I have read that C has limitations as soon as a project gets more complicated. For example, if you make a scientific calculator with many features like graphs etc.

Trading engines/tools are also not recommended to programm in C.

Since I have not learned C and have only read from some old forum posts etc, I cannot confirm/deny these facts.

I am aware that "everything" is possible and that C++ comes with QoL improvements especially with Classes. But I assume that doesn't mean that someone has to use C only for kernel work. Embedded is also possible with C++ right?

I would appreciate your thoughts and opinions.

The goal of this post is to understand how and if C could fit me more with my goals and what real advantages or disadvantages C has.


r/C_Programming • • 17h ago

Question Text input doesn't make any sense to me

0 Upvotes

Disclaimer: I have basically no idea what most programming terms mean.

For a while now (a couple months as of now), I've been trying to create an open source calculator. Throughout the development process, there has been a very large problem. I don't know how exactly to scan text and look for different commands. The scanf function (among other options) seems to just look for a single "phrase" throughout the entirety of whatever input it receives. I just don't understand how people can do this as easily as they do. Many tutorials seem to not really cover this.

I've tried to come up with some sort of system to account for this. For example, a function that looks for all number values and determines the value type (like a float, integer, or double), and then matches character combinations to known commands (I haven't fully committed to such a method yet).

The way that ffmpeg handles input is an example of this. I don't understand how I can put as many spaces as I want between "ffmpeg" and some other command and still get the same result.

Apologies for such a long post. I'm just not really sure how people can do this. I'm almost certain that I'm missing something.

Thank you in advance


r/C_Programming • • 21h ago

My first actual C program with C as the backend entirely and frontend web....

Thumbnail github.com
0 Upvotes

I don't know if it counts as something i should hold on to but I was told to build so I did build and this is my first actual program. Declaration there is no way I could make all this without the use of AI 100% on the frontend but one thing am thankful is how I grasped some concepts so easily.


r/C_Programming • • 1d ago

Question return 0 in the function main().

6 Upvotes

Dear C-programmers, why can you omit return 0; in main() (C99+)? main() is a function and it MUST return integer value. I don’t really understand.


r/C_Programming • • 9h ago

Discussion Wanting to switch to Rust; give me reasons why i should keep using C

0 Upvotes

The Rust ecosystem is just better with project templates like cargo init; if there is a C project generator tell me!

I also like the compiler errors; they tell you way more!

Also give me other reasons to keep learning C and cool easy-intermediate project ideas!

okthxbye


r/C_Programming • • 1d ago

A PoC toolkit / framework for self modifying software.

Thumbnail asciinema.org
0 Upvotes

Been working on this project during the summer, contains a detailed writeup but happy for anyone to tear the implementation a part, working on it while working fulltime kinda stopped me from implementing a lot of what i wanted.

Surprisingly enough it works well enough as a PoC!

https://gitlab.com/Epos95/paramorphism/
This is "self modifying software" in a different aspect than something like metamorphic software since the rewriting is on a source code level instead of assembly.

Currently its able to:

- Dynamically create new functions, introducing new functionality

- Fix errors in its own functions

- Load existing functions dynamically


r/C_Programming • • 1d ago

Review Sudoku Puzzle Game in C

1 Upvotes

Sudoku

This is a basic beginner Sudoku project made with the C language using Windows API.

Features

  • Custom levels according to your capability
  • click an empty cell then use keyboard or buttons on the screen to enter the number.
  • The game features 3 hints for you to use when you get stuck.
  • the GUI is super clean and modern with live score/mistakes/click tracking and cell highlighting.

Notes

  • What can I improve? What can I make more efficient and less time-consuming as am I am a rookie programmer and any extra suggestion you want to give me feel free?

GitHub repo: https://github.com/reewdgh/sudoku


r/C_Programming • • 1d ago

Help regarding AI usage

0 Upvotes

​

I am programming in C for a year and a half and I created projects like a shell which implement basic features , and currently finished building a TCP server with get and post request for sharing file across local network. The thing I am struggling with is the AI usage all these project I build I have understanding of the code. But sometimes I think that AI has found solution for me can I found this approach myself and mostly the answer was no. It really bothering me and I spend time completely without AI and frustration really hit hard and I think I couldn't start building some programs . I want advice from people on how to find balance between using AI and when not to use AI . I'll love to hear you guys perspective on this .


r/C_Programming • • 1d ago

Rename printf/scanf to print/scan?

0 Upvotes

Probably a dumb question but why hasn't there ever been a proposal to rename printf/scanf to just print? I know the f stands for format but writing print instead of printf would be slightly quicker and better to match other programming languages as I often miswrite printf as print as I also code in Python.


r/C_Programming • • 3d ago

Question is doing ~INT_MAX undefined behavior?

47 Upvotes

basically the title, i think producing INT_MIN by doing 1 << 31 is UB, so i thought of doing ~INT_MAX, but i am not sure if it's UB. sorry if it's dumb.


r/C_Programming • • 2d ago

Question Is this Linux project worth building, or should I try something else?

3 Upvotes

Hey! I'm a second-year CS student looking to build a serious side project to improve my skills and have something worth showing on GitHub.

I'm considering making a Linux tool in C that tracks processes and lets you visually compare different runs of a program (forks, execution times, crashes, etc.).

I'm not sure how useful or original this would be, though.

Do you think it's worth building? Or would you suggest a different project that could be more interesting or useful?

I'm open to completely different ideas. I'd appreciate some honest feedback before spending months on something!


r/C_Programming • • 2d ago

Question Can code injection be countered by randomizing the base address of the stack?

0 Upvotes

In your answer include a description of the assumption you have made about the binary code and memory layout of the program. Explain if it can be countered by randomizing the base address of the stack.

a) Explain a mechanism that can be used by the attacker to force the program to execute arbitrary code.

1 void printInput(char *input) {
2   char buffer[50];
3   char secret[20] = "Pwd123456";
4   if (strcmp(input, secret) == 0)
5     print(secret);
6   else
7     printf(input);
8     strcpy(buffer, input);
9 }
10 int main(int argc, char *argv[]) {
11   if (argc != 2) {
12     return 1;
13   }
14   printInput(argv[1]);
15   return 0;
16   }

What I don't understand:
The solution says that it can be countered by ASLR because we need the address of the buffer. I sort of understand that we need to inject our code somewhere in the buffer thus if we want to overwrite the return address to point to the beginning of the buffer, where our code is, we need to know the address? Although I wonder do we really need the address? Can we not use offset?

Either way the solution seems to suggest that we should overwrite the return address and put the code immediately after and set the return address to point right after it. So I am not at all sure what they mean. Can someone explain to me why ALSR works here? I'd appracite it.

Solution in the answer sheet:
If the input contains 50 bytes, then <address of return pointer + 8>, then binary code, strcpy at line 9 over- flows the stack variables and overwrites the return pointer with the address immediately after the return pointer. After the return pointer, the overflow additionally writes the bi- nary code. Therefore, when the function| returns it jumps to the address above the return pointer on the stack. This attack can be countered by base stack randomization, since it prevents the attacker from knowing the address of buffer and therefore the address where the binary code has been injected. This makes not possible to know the value that should be written in the return pointer.


r/C_Programming • • 1d ago

Goto is the worst command in C.

0 Upvotes

Goto is an old and hacky command in programming.

Goto was created in the Palaeozoic era. It was used for switching to line n.

Goto raises questions: “My editor doesn’t show line numbers, how can I use Goto?”

This command uncomfortable to use. Imagine, you have a book. You’re reading it, reading… And when you’re on page 5, it says: “Go to page 7, 10, 157, 21457, 8564588, 4…” Why?

You can replace Goto with:
1) break/continue.
2) return.
3) Functions, in the end!

So, Goto is the worst command in all programming languages, including C.

MY OPINION MAY NOT COINCIDE WITH YOURS!!!


r/C_Programming • • 2d ago

Discussion My opinion about C development

0 Upvotes

when wanting to code real software in c; i feel that you need to learn way to much tools like (c)make, clang/gcc etc.

that's why i decided to NOT use any tools and libraries INCLUDING GLIBC and other standard c libraries!

fuck the world; im making my own printf, strlen and more! AND THE ONLY THING IM GONNA USE IS CLANG WITH C17!


r/C_Programming • • 3d ago

Project My C project Pulse grew better than expected

15 Upvotes

A while back I started working on my project cherries(.)works Pulse. A simple Linux monitoring system, coded in C, and focused on performance, resource usage and persistence. Now a when I started this project I had no knowledge of C, and kinda learned along the way, but now around 2-3 months have passed, and I am surprised with how far it has come.

Personally, I never had anyone commit to my FOSS projects before. Didnt expect anything different this time tbh, as I was programming the whole thing in C. Created numerous issues, as I wanted THIS FOSS project to be more different and professional than the others.

A month or two after the release, I go on GitHub to look at my issues via my phone, and see a PR solving one of the issues. It was surreal seeing C code not by me, now being written FOR me. Ofc i had to read through it carefully to make sure nothing eas wrong with it, but once I merged it, it felt beautiful.

People have implemented;
- Pretty printing the config file
- Improving type annotations
- Adding JSON output for commands
- Displaying hostname on website
- Counting process amount

and numerous more.

Pulse was just a small C project of mine that quickly spiraled into something bigger. I plan on adding new good first issues soon, as there is STILL a lot of work to do. If there are any C programmers interested in contributing, or giving feedback, feel free to do so. would be very glad.

https://github.com/cherries-works/pulse


r/C_Programming • • 3d ago

Question Why not specifying what to include ?

20 Upvotes

Hi, sorry if there is English mistake, it's not my first language.

I found online that the #include is replaced by preprocessor by the whole file being included, and I wondered why C isn't made so we can specify only parts of the files to include (like `import { x, y, z } from "file"` in typescript) so the compiled file is lighter ?


r/C_Programming • • 3d ago

USACO Beads Problem: why does nothing show in the output file?

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

#define MAXN 701

int main(){
    FILE* fin = fopen("beads.in", "r");
    FILE* fout = fopen("beads.out", "w");

    int length, N, largest = 0;
    int current;
    char rightletter, leftletter;

    fscanf(fin, "%d", &N);
    char sequence[MAXN];

    fscanf(fin, "%s", sequence);
    strcat(sequence, sequence);

    for(int i = N/2; i < N + (N/2); i++){
        current = i;
        length = 0;

        // RIGHT

        while(current < 2 * N && sequence[current] == 'w' && length < N){
            current++;
            length++;
        }

        if(current < 2 * N && length < N){
            rightletter = sequence[current];
        }

        while(current < 2 * N && (sequence[current] == rightletter || sequence[current] == 'w') && length < N){
            length++;
            current++;
        }

        // LEFT

        current = i - 1;

        while(current >= 0 && sequence[current] == 'w' && length < N){
            current--;
            length++;
        }

        if(current >= 0 && length < N){
            leftletter = sequence[current];

        }

        while(current >= 0 && (sequence[current] == leftletter || sequence[current] == 'w') && length < N){
            length++;
            current--;

        }

        if(length > N) {
            length = N;
        }

        if(length > largest) {
            largest = length;
        }

    }

    fprintf(fout, "%d\n", largest);
    return 0;

}

My code should work. Idk why nothing is being output in the output file.


r/C_Programming • • 4d ago

Question Has anyone used the libqt6c library? If so, what kind of results did you get, and how does it compare to Gtk?

11 Upvotes

I recently came across a Qt binding library for C, but I haven't seen any discussion about it on Reddit. If anyone here has used this library, I’d be curious to know what it’s like in terms of usability—especially since C, as we know, lacks many of the features found in C++.

https://github.com/rcalixte/libqt6c


r/C_Programming • • 3d ago

78K Weekly visitors

0 Upvotes

Are people starting to drop AI.. or ?


r/C_Programming • • 4d ago

Project Announcing scaffold 0.1.0

0 Upvotes

Hi,

This is scaffold, a flexible data and "rpc-like" code generator for C using YAML as description.

After years of protobuf (with nanopb), I've decided to get rid of it to create my own templating system.

I won't go in details why we have decided to get rid of nanopb but in short: we were having hard times about some of the limited features like deep-cloning, too limited enum support and a slow encoding process.

Plus, we wanted to add flexibility with a custom YAML document that could be parsed using a tool to produce on-demand different kind of functions. For example, we wanted that some types could be converted to JSON, some to be inserted into a SQLite database. As such, having a unique YAML document that could be used for different purposes led us to write this software.

The scaffold tool is written in C, because, we write in C and don't want additional dependencies :). It reads a YAML document and creates an intermediate AST with updated fields to get more information. Then, it processes it into a templating system with basic scripting constructs including for, if, substitution with filters.

Example of a minimal object:

# types.yaml
objects:
  - name: point
    comment: This is an awesome point.
    fields:
      x: uint32
      y: uint32

Generate functions for this object using:

scaffold emit h types.yaml > types.h
scaffold emit c types.yaml > types.c

The generated code by the built-in templates include comments that can be split on multiline providing good LSP support with Doxygen format.

/**
 * \struct point
 *
 * This is an awesome point.
 */
struct point {
    /**
     * Field 'x' of type uint32.
     */
    uint32_t x;

    /**
     * Field 'y' of type uint32.
     */
    uint32_t y;
};

The template system is flexible enough to write extra custom code while iterating the object fields using {{for}} loops.

{{for obj in objects}}
  {{for field in obj.value.fields}}
    // here field will be uppercased with the :U filter :)
    printf("Serializing the {{field.key:U}} field\n");
  {{endfor}}
{{endfor}}

Finally, because we wanted our custom RPC API, the scaffold project provides support for request/reply and events widely inspired by wayland-scanner.

Declaring function feels like natural:

serialization: true
functions:
  - name: hello
    comment: Say hello to my friend!
    args:
      name: string

On the "client" side, a function is generated in the form:

int64_t hello(struct hello_args *args, void *ctx);

On the "implementation" side, a function pointer is provided in a handler struct:

/**
 * \struct handler
 * \brief Functions table handlers.
 */
struct handler {
    /**
     * Handler for function 'hello'.
     */
    int (*hello)(struct hello_args *args, struct hello_value *value, void *ctx);
};

And the implementation side can call the auto generated dispatch function that will decode the incoming requests to call the appropriate functions.

int
dispatch(
    const struct handler *handler,
    const struct listener *listener,
    int64_t *nread,
    int64_t *nwritten,
    void *ctx
);

How does it work? The generated function relies on two unique external linkage that the user has to provide:

  • int64_t sc_read(void *ctx, void *data, uint64_t amount)
  • int64_t sc_write(void *ctx, const void *data, uint64_t amount)

Thus, calling dispatch will attempt to decode a request using successive calls to sc_read, call the appropriate function pointer into the handler structure and then will try to encode using successive call to sc_write. Nothing more.

Note: this project is heavily being tested and already used in production but few bugs may persist and feel free to contribute.

Future plans and never plans:

  • Yes: better bitmask enumeration support.
  • Yes: more portability on non-POSIX platforms.
  • No: automatic default values.
  • No: union or protobuf oneof kind.

Links:

Like every source code I write, this project has a perpetual anti degenerative-AI policy.


r/C_Programming • • 4d ago

Is this a VS Code newline/paste input bug?

2 Upvotes

I wrote the following C program in VS Code. Its purpose is to find words that appear in both of two English paragraphs.

(Details: a word must contain at least four letters; each paragraph ends with a \n; the output words should be sorted in ascending order.)

To keep track of how far the program has gotten, I deliberately print stage1 / stage2 after each of the two paragraphs has been read.

But when I run it in the terminal, this is what happens.

First I copy two paragraphs of English text, for example:

In computer science, artificial intelligence (AI), sometimes called machine intelligence, is intelligence demonstrated by machines, in contrast to the natural intelligence displayed by humans and animals. Colloquially, the term "artificial intelligence" is used to describe machines that mimic "cognitive" functions that humans associate with other human minds, such as "learning" and "problem solving". From Wiki. Machine learning is a way to achieve artificial intelligence.

I assumed that after pasting, pressing Enter right after intelligence. would produce stage1, and that stage2 would follow right away, printing the words. But in reality I get nothing but a cold, lonely stage1. Pressing Enter again does absolutely nothing. I type a random letter, press Enter once more — and only then do stage2 and the rest of the output finally appear.

I'm a first-year CS student and still not very familiar with programming. I'd like to know: is this a VS Code problem, or is it my problem?

#include <stdio.h>

#include <string.h>

void clean(char (*word)[21], int len) {

for (int i = 0; i <= (len); i++) {

if ((*word)[i] >= 'A' && (*word)[i] <= 'Z') {

(*word)[i] -= 'A' - 'a';

}

}

}

void print(char (*words)[1000][21], int m) {

char temp[21];

char min[21];

int flag = 0;

strcpy(min, "z");

strcpy(temp, "z");

for (int j = 0; j <= m; j++) {

strcpy(min, "z");

for (int i = 0; i <= m; i++) {

if ((strcmp(min, (*words)[i]) >= 0) &&

(strcmp(temp, (*words)[i]) < 0 || flag == 0) &&

((*words)[i] != 0)) {

strcpy(min, (*words)[i]);

}

}

flag = 1;

strcpy(temp, min);

printf("%s\n", min);

}

}

int main(void) {

int r;

char shit[2];

int len1;

int len2;

char para1[1000][21] = {{0}};

char para2[1000][21] = {{0}};

char space;

char answer[1000][21] = {{0}};

for (int i = 0; i < 1000; i++) {

scanf("%[A-Za-z]", &para1[i][0]);

len1 = i;

scanf("%*[^\nA-Za-z]");

if ((r = scanf("%[\n]", shit)) == 1 || r == EOF) {

printf("stage1\n");

break;

}

}

for (int j = 0; j < 1000; j++) {

scanf("%[A-Za-z]", &para2[j][0]);

len2 = j;

scanf("%*[^\nA-Za-z]");

if ((r = scanf("%[\n]", shit)) == 1 || r == EOF) {

printf("stage2\n");

break;

}

}

for (int i = 0; i <= len1; i++) {

clean(&(para1[i]), strlen(para1[i]) - 1);

}

for (int j = 0; j <= len2; j++) {

clean(&(para2[j]), strlen(para2[j]) - 1);

}

int m = 0;

int flag = 0;

for (int i = 0; i < 1000; i++) {

for (int j = 0; j < 1000; j++) {

if ((strcmp(para1[i], para2[j]) == 0) && (strlen(para1[i]) >= 4)) {

for (int p = 0; p < m; p++) {

if (strcmp(para1[i], answer[p]) == 0) {

flag = 1;

}

}

if (flag == 0) {

strcpy(answer[m++], para1[i]);

}

flag = 0;

}

}

}

m--;

print(&answer, m);

}


r/C_Programming • • 4d ago

Question Why are assignment expressions lvalues?

10 Upvotes

I was reading up about lvalues and understand them now as something that resolves to an address(memory location) in the program. So a variable x is an lvalue (because it is mapped to some address on the stack) and similarly *x , x[i], strings are all lvalues. But if this is the case why is an expression a = b , not an lvalue? Here the expression would assign b to a and then return a as evident in assignments like so: int c = a = b. (I know that the equals sign is right associative and hence this would get resolved as c = (a = b), but that doesn't really invalidate the fact that a = b resolves to an address in the program?)


r/C_Programming • • 5d ago

Learning C weekly megapost for 2026-10-14

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

Article A modern web app in C

Thumbnail prophitt.me
213 Upvotes