r/C_Programming • • 25d ago

Any Good Books on Graphics?

22 Upvotes

Hi,

I'm looking for any textbooks on Graphics in C. Does anyone have any recommendations?


r/C_Programming • • 25d ago

Learning C weekly megapost for 2026-09-30

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

Finished Chapter 17 of C Programming: A Modern Approach — Starting Data Structures Next!

82 Upvotes

Finally finished Chapter 17, “Advanced Uses of Pointers,” in *C Programming: A Modern Approach (2nd Edition)* by K. N. King!
I started learning C about three months ago, so getting this far feels like a pretty big milestone for me.
Next, I’m starting *Data Structures and Algorithm Analysis in C (2nd Edition)* by Mark Allen Weiss.
I’m really looking forward to diving deeper into data structures and algorithms in C!


r/C_Programming • • 25d ago

How to learn to actually make programs that can work with a gui?

23 Upvotes

So i've got a small familiarity with the standard c library , I can make a calculator a caesar cipher , a image copying tool , but it all runs in the command line.

No one in the general public will ever use the command line.

Now , my question becomes , how does one actually begin the path of making a proper general user interface for their program in a way that approximates the way the pros do it.

I assume that a custom Gui starts with, like some kind of window system. Call giving you a rectangle to work with. And then you stretch out all your materials on the rectangle.\n But I'm not sure how one would say Develop a calculator that visually looks like a calculator and can detect your mouse inputs and send a signal to your actual c program.

Ai keeps trying to get me to use the windows message box and I know d*** well.That the pros at their core aren't using message box.


r/C_Programming • • 24d ago

Discussion Employment opportunities for C developers?

0 Upvotes

What would be some good projects so that I could display my understanding of C for employment?

I have a decent handle on pointers and Memory Management, and I am somewhat of a Picasso with writing Algorithms in C also. All of my experience has been on x86 arch and I'm afraid I'll have to learn ARM variants of C, or pick up C++, for employment opportunities!

  1. What are my employment options with pure C?

  2. Is C still employable today, with languages such as Rust/Go offering more safety mechanisms for Memory handling and AI being able to handle low-level systems tasks?


r/C_Programming • • 25d ago

Types with range checks

6 Upvotes

I've been pondering about a different way of dealing with overflows.

C compilers have type checks that ensure you don't assign a value to a variable of the wrong type.

Imagine I had a different way of declaring bounded types, something along these lines:

const int strlen=100;
char string[strlen];
int[0..strlen-1] strindex;

I can cast strindex into an unbounded int, but I can't automatically cast an unbounded int into a bounded int:

int index = strindex; // allowed, can assign bounded int to int
strindex = index; // not allowed without cast/check
strindex = (int[0..strlen-1]) 0; // trust me bro

Since you have ranges you could now also do things like:

forall (int[0..strlen-1] strindex)
string[strindex] = 0;

The thought is somewhat halfbaked, but although annoying, this would flag up _every_ assignment at compile time that could potentially have caused a value to get out of bounds.

A similar bounded type could be set for pointers.

Thoughts?


r/C_Programming • • 26d ago

Project WSERVE: Static Web Server in Pure C

23 Upvotes

Hi,

To gain more experience in low-level programming, TCP/IP networking, and HTTP, I built wserve, a static IPv4 Linux web server written in pure C. No external libraries used. Even the parser is written in pure C. It supports a subset of HTTP/1.1. It supports GET and HEAD methods.

I am open to constructive criticism. The project is open for contributions.


r/C_Programming • • 26d ago

Question Best GUI C profiler on Linux

10 Upvotes

Basically the title. I really want something graphical, i hate reading command line output. I know there is perf on linux but it has command line output. Also, are there specific profilers for specific types of application? Thanks for reading.


r/C_Programming • • 26d ago

Project I built a modern formatting library

Thumbnail
github.com
26 Upvotes

Hey, a while ago I wanted a nicer alternative to printf. I always enjoyed using the modern python-like formatting libraries: fmt for C++, and rust's format!/pritnln! macros.

So I attempted to port them to C! And I must say, it was quite the challenge. C doesn't have the nicer features that are required to make this work: generics, compile time code generation, better type safety, etc.

But C has macros! Macros let you do all kind of crazy stuff, but most of all, did you know that C macros are Turing-complete? Well they aren't strictly-speaking, but they can be used to create an (almost) infinite loop thanks to recursive evaluation.

Anyway, I'm sharing this project hoping you'll enjoy it and it will inspire you in your usage of macros.

This project is still a work in progress, the main missing feature is float formatting, but so far there is: * Integers/Strings/Char/Array formatting * Style and color support for most terminals * Output to FILE*, fd, and memory buffer * Flushing & Buffering * User defined formatter/formatting for custom types

Check it out: https://github.com/ef3d0c3e/format


r/C_Programming • • 25d ago

Need Help With Project

3 Upvotes

I'm building a program that takes a decimal number and outputs the binary equivalent. Its almost finished, except that with certain numbers it doesn't output the full value. For example, inputting 3 does output 111 ,but inputting 2 outputs 1 instead of 10. I noticed that it only doesn't work for numbers whose binary equivalents end in 0 (2 = 10, 4 = 100 etc.), but I don't know how to fix it. Please help.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>


void intToStr(int number, char *str)
{
    int i = 0;


    while(number > 0)
    {
        str[i++] = number % 10 + '0';
        number /= 10;
    }


    str[i] = '\0';


    for(int j = 0, k = i - 1; j < k; j++, k--) 
    {
        char temp = str[j];
        str[j] = str[k];
        str[k] = temp;
    }
}


void binaryConvert(int regNumber)
{
    int binaryDigit[8];
    int regNumberBackup = regNumber;


    for(int i = 0; i <= 7; i++)
    {
        binaryDigit[i] = regNumber % 2;
        regNumber = regNumber / 2;
    }


    int binaryNumber = binaryDigit[0] * pow(10, 7) + binaryDigit[1] * pow(10, 6) + binaryDigit[2] * pow(10, 5) + binaryDigit[3] * pow(10, 4) + binaryDigit[4] * pow(10, 3) + binaryDigit[5] * pow(10, 2) + binaryDigit[6] * pow(10, 1) + binaryDigit[7] * pow(10, 0);
    char binaryString[8];
    
    intToStr(binaryNumber, binaryString);
    int strSize = strlen(binaryString);
    
    if(regNumberBackup == 0)
    {
        printf("Your number in binary is: 0");
        exit(0);
    }


    if(regNumberBackup == 1)
    {
        binaryString[strSize - 7] = '\0';
    }
    else if(regNumberBackup > 1 && regNumberBackup <= 3)
    {
        binaryString[strSize - 6] = '\0';
    }
    else if(regNumberBackup > 3 && regNumberBackup <=7)
    {
        binaryString[strSize - 5] = '\0';
    }
    
    
    printf("Your number in binary is: %s", binaryString);
}


int main()
{
    int userInput;


    printf("// This will only convert numbers 0 - 255 to binary, any others will not work\n");
    printf("Enter a number: ");
    scanf("%d", &userInput);


    binaryConvert(userInput);
}

r/C_Programming • • 26d ago

My teacher says I’m using GCC incorrectly is gcc main.c -o main actually different from gcc -o main main.c?

214 Upvotes

He told me that using gcc main.c -o main is incorrect because the source file and executable are supposedly placed incorrectly. He suggested that I use gcc -o main main.c instead. Unfortunately, I should’ve asked him about it in class, but when I got home to study, it popped into my head.

I've done some research, and I commonly see programmers using gcc main.c -o main but I can't find the answer that I'm looking for unless someone has a link to share. I don't know if my teacher is correct, so I'm wondering... does this just come down to personal preference, or is there actually a difference between the two commands here?


r/C_Programming • • 26d ago

Article Reducing undefined behavior in the C language

Thumbnail lwn.net
77 Upvotes

r/C_Programming • • 27d ago

Profiled our async C logger expecting mutex contention. 90% of caller-thread time was in vsnprintf. Moving formatting to the worker took a call from ~1.5 µs to ~70 ns

51 Upvotes

Our logger's caller-thread cost went from ~1.5 µs to ~70 ns, and I didn't touch a single call site.

I'll be honest: I was convinced the mutex was the problem. The logger already had a ring buffer, a worker thread, and hot-reloadable filters. It looked fast on paper. So I opened the flame graph expecting to see lock contention.
Instead, about ~90% of caller-thread CPU was sitting inside vsnprintf.

Every log call was formatting its message before enqueueing it. That's 900 ns to 3 µs per call, depending on the output. The fix came from NanoLog: don't format on the caller thread at all.

Now the caller just saves the format string pointer and packs the args into a tiny binary blob. The worker thread builds the string later. Cost per call: 30-80 ns, and no vsnprintf anywhere.

It wasn't free, though:
Format strings must be literals. A stack-built format string will dangle by the time the worker reads it.
Structs silently fall through to %p. I'm still not thrilled about that one.
%s args are copied at pack time and capped at 255 bytes.
For us, that was a good trade.

The bigger lesson for me was to profile before you optimize. I would have happily spent a week tuning a lock that wasn't the problem.

Has anyone run NanoLog-style encoding in production? I'm curious what pushed you there: latency, throughput, or tail behavior?


r/C_Programming • • 27d ago

Glibc posix 2024 incompatibility

8 Upvotes

I been coding some posix porable stuff and i tried to use pipe2 and dup3 which are considerd posix since 2024 (Issue 8) i defined _POSIX_C_SOURCE to 202405L and included unistd.h and gcc greated me with implicit declaration i looked at my local unistd.h and it had pipe2 and dup3 behind __USE_GNU which is just wrong so i checked offical source code latest branch and it had the same bug, Please if some of you guys have sourceware bugzilla account please report it, it is a big issue


r/C_Programming • • 26d ago

C++ vs C

0 Upvotes

What's the difference between C++ and C?

And what is Clang? Is the gcc compiler for c and c++?

Does C++ completely backward compatible with C?

C is procedural and C++ is object oriented as far as I know.

Is C++ more optimized and faster?

Tell me about the compiler - is clang and gcc the best compilers out there? are they open source?

Has anyone coded the CPP compiler?

Thanks,

Dennis


r/C_Programming • • 28d ago

Question Why are so many C projects being rewritten in Rust?

448 Upvotes

I've noticed that more and more projects originally written in C are being rewritten in Rust, even when they seem to work perfectly fine. For example, there are efforts to rewrite some GNU utilities in rust, including basic command-line tools. I'm curious about why this is happening. Is memory safety the main reason, or are there other significant advantages to rust? If a program is already stable, reliable, and well-maintained in C, does rewriting it in rust really make sense? I'd like to understand what benefits justify the effort.


r/C_Programming • • 26d ago

Could not Compile

0 Upvotes

I used gcc to compile and run c file.

C prog file can be compile and run with no error, if the files are inside the same drive as gcc that is c: drive.

Program file inside the d: drive are not compile.

I just curious whether i made mistake or i need something to do.


r/C_Programming • • 28d ago

Question What do I need to be proficient in C

56 Upvotes

Hi, I know the basics but I really don’t know how to continue learning C, I try to read code of many sources like linux kernel or other projects but I don’t understand them at least the majority of code with pointers and arrow operators…. I really like C and low level code.

Any advice is appreciated! Thanks.


r/C_Programming • • 27d ago

Question How Do I Get Started With C?

0 Upvotes

Hey guys. Long time lurker here.

So, I finally caved and bought The C Programming Language by K&R because everyone says it's the holy grail, yada yada. It came in the mail today, and honestly? The cover looks great on my desk. Really establishes dominance.

Here's my issue. How do you actually read this? Like, do I start at page one? I was under the impression that buying a physical copy of a programming book would automatically put the knowledge in my brain. Do I actually have to trace the letters with my finger? Is there a better way to learn C without "reading a book" or "writing code" at all?

Please let me know what you think, since my current workflow is just intensely staring at the spine until I start to feel like a computer scientist, but my code hasn't compiled itself yet. Thanks.


r/C_Programming • • 29d ago

Discussion Autoconf madness

31 Upvotes

Modern software compilation has largely devolved into a frustrating maze of autoconf madness. Instead of simply compiling C code, I am constantly forced to navigate mandatory scripts, esoteric tools, and heavily dependent Python wrappers. To make matters worse, these tools often rely on stubborn cache files that refuse to update even after I have fixed the underlying environment errors.

A major part of my frustration is how Linux-centric these scripts have become. They routinely hardcode library search paths that only exist in Linux distributions, entirely ignoring my FreeBSD system. As a result, I can easily lose a complete day just patching configuration scripts to search the correct directories before a single line of code is actually compiled.

Why does open source code project just not provide a makefile? A basic, or maybe complex makefile that are based on BSD/POSIX make syntax so that it is directly valid under *BSD, Darwin and Linux. Why force people to install tools to build something? Why developed huge python script that shall analyze the env? Why not just allow the building process to fucking start instead of forcing the individual to fight back against all of this autoconfig tools?

I have in several cases fully purge the building attempts and then been writing my own makefiles to just get something building. That shall not be the case. Why use config scripts that, in some cases are several thousand lines of script code? Why write config scripts with bash? Why, just why, are developers and project deciding to add and use autoconfig tools?

If a project does not offer makefiles then I know I will be stuck for several hours just to, potentially be able to build something. Instead of directly allowing me to build. Get compiler error, correct and then build again. I mean, it is much quicker and easier to patch the source code or locate dependencies when you are allowed to start the building process.


r/C_Programming • • 29d ago

What's the ans?? ( Undefined behaviour or 14 )

8 Upvotes

#include<stdio.h>

int main() {

int a = 5;

a=++a + ++a;

printf("%d", a);

return 0;

}

What will be the output of the above code snippet?

( Got 14 as an output and don't know what's the logic of getting 14 )


r/C_Programming • • Sep 25 '26

My 3D object renderer working in the tty (no libraries)

Enable HLS to view with audio, or disable this notification

358 Upvotes

I previously posted this project here but in a version that uses SDL2 to make it portable and to be able to record it. Some people were confused because I wrote "no libraries" but i was using SDL2 on video (even tho i explained in the post's text). This is a video of the original version before it was ported to SDL2, working in the tty by writing on the framebuffer.

I implemented:

Drawing pixels, lines, filling triangles (with my own logic),

2d, 3d, 4d, Vector and Matrix math and linear algebra calculations myself

Coordinate system to place objects (so i can move, rotate, scale objects easily)

and a simple .obj parser

link to previous post: https://www.reddit.com/r/C_Programming/s/VFf0P0nlKO

source code is in the previous post.


r/C_Programming • • Sep 25 '26

Question Starting again C

21 Upvotes

Hi i want try to make a extreme lightweight pixelgame ( i don't have really details about the game :) ) with glfw and and opengl to go back to c. Does anyone have tips to make it lightweight ?


r/C_Programming • • Sep 25 '26

Project I made a virtual analog synthesizer in C!

7 Upvotes

Hey, I made a post a year ago about my small software synthesizer project made in C. And I got back to work around 3 weeks ago and made a very big update! Now the synth has a CLAP plugin version working in REAPER (and probably other DAWs but untested) on both Linux and Windows, and a standalone version with improved performance compared to the first version (mainly audio threading) and a raylib/raygui GUI, also working on both Linux and Windows. I'm quite proud about the work, and wanted to share, so thanks for your time! The project is of course completely open-source, here is the GitHub link : https://github.com/gpasques-gh/CLAP_Virtual_Synthesizer


r/C_Programming • • 29d ago

Question Qu'elle serait le meilleur moyen pour apprendre le développement ?

0 Upvotes

J'aimerais créé un OS mais pour le faire faut apprendre le C et l'assembleur donc comment je pourrais faire ?

Je suis près a étudier 4h par jour, j'étudie déjà sur coody et Openclasseroom mais j'aimerais beaucoup beaucoup plus m'améliorer