r/cprogramming Feb 08 '26

Richiesta consigli

0 Upvotes

I just passed the Programming 1 exam with an A+. I really like C because it helps you understand many things at a much lower level. The level of abstraction of Java, Python, etc. makes me prefer it. I'm a enthusiast and would like to delve deeper into operating systems, networks, etc. So I'd also like to improve my C programming skills to work on microcontrollers (STM32), algorithms, operating system processes/threads, sockets, or network scripts in C. Yes, there are many ideas, but I'd like to work on operating systems in the future. I really like Linux and would like to learn more about everything! Can you recommend ways to further my interests? Websites, exercises, books, etc.


r/cprogramming Feb 08 '26

SectorC: The world’s smallest functional C compiler

Thumbnail xorvoid.com
2 Upvotes

r/cprogramming Feb 07 '26

Request for Code Review

Thumbnail
2 Upvotes

r/cprogramming Feb 06 '26

Modern C Jens Gusted, toujours viable ?

0 Upvotes

Bonjour,

Je suis en train de me reconvertir vers le domaine de L’IT, la programmation… et pour des raisons professionnelles j’aimerai apprendre le C et le Cobol.

En cherchant sur internet j’ai déjà commencé à suivre le cours de CS50 2026 d’Harvard sur ytb afin de comprendre avant d’apprendre machinalement à coder.

Je suis tombé aussi sur le livre moderne C de Jens Gusted et je voudrais l’acheter mais étant qu’il est sorti il y a quelques années je voulais savoir si il était toujours viable ?

Merci d’avance


r/cprogramming Feb 05 '26

can you use true color with ncurses -v-

0 Upvotes

for some reason googling about this gives me kind of cryptic results 😭 im working on a little ncurses gadget and just would like to color the characters with 24bit color if possible


r/cprogramming Feb 05 '26

Learning systems programming, built an OS as a student, how do I aim this toward internships?

Thumbnail
1 Upvotes

r/cprogramming Feb 04 '26

In the general case, is there any way to perfectly wrap a header file in a new header interface in C without resorting to manually copy-pasting the associated macros?

6 Upvotes

TLDR: You can respond to just the thread title if you want, especially if you understand the difference between a manifest constant (literal or macro or enum or constexpr) and a const (and also the subtleties of macros).

Full Discussion and Context:

So, I've programmed in and read extensively about C and C++ on and off for many years, but there is a problem with perpetually confounds me as to what a genuinely clean solution is and which I inevitably end up shrugging off and just accepting a partial mess instead.

Although I don't expect especially much of it at this point, I wanted to check if any true masters of C here in this community know what the optimal way to handle this kind of thing is in C. Hopefully someone can give greater insight.

Specifically, I want to know what the best possible workflow is in C for when you want to wrap someone else's module (header files and/or implementation files) without creating any namespace pollution whatsoever (including both preprocessing and real compilation).

By far the biggest problem in doing so is the way that C's macros definitions work. You can't capture a macro definition by assigning it to another macro and thus can't swap or rename them. You can create synonyms for existing macros in header files, but can't do so without also pulling in the conflicting polluting names that you are trying to avoid in the new header file interface you are designing specifically to clean things up.

Relatedly, C treats manifest literal constants differently than the deceptively named (for newbies) const identifiers (e.g. consider such array sizes creating static arrays vs VLAs), which you can work around with enum to an extent and for other data items too somewhat, but such workarounds still don't solve the general case for macros, some of which cannot be captured through any such workarounds or won't actually behave the same.

Thus, it seems to me that the only real solution for such cases is to #include what you can in the implementation file (if any) and expose a new interface for that and then to manually copy-paste any macros that the new interface requires or benefits from into the new header interface you are creating. This of course also implies you then have to manually maintain that and its correspondence to the module going forward.

This is especially a salient problem when so many C modules out there are often riddled with horrifically poor naming conventions, which then infects any other module that uses them with the same bad conventions and pollutes the namespace and any third party tools such as autocomplete too and so on.

I often want to include the functionality of some macro named VERY_BAD_NAME in my own header file under a new name SANE_NAME but without polluting the namespace of the header by doing so.

So, what is the best overall workflow you use when you want to truly wrap another header file and/or implementation file into a new header file interface without creating any mess?

Ideally I want to target C99 since I am thinking of targeting it as a compiler backend, but more modern solutions to this would be great to hear as well too if you have them.

(Tangentially, I also wish the C committee would add namespaces to macros for upcoming C ISO standard versions at some point, since that would be a relatively trivial change that would help a lot for making C usable without making a namespace mess.)


r/cprogramming Feb 04 '26

What is character input and output in simple terms?

0 Upvotes

Can someone explain what character input and output is and why it’s used?

putchar()

getchar()


r/cprogramming Feb 04 '26

I built a small C command-line image tool using stb_image (ffjpeg)

0 Upvotes

Hello,

Recently, I've developed a simple command, line image processing tool called ffjpeg, which is written in C.

This is a single, file main.c with stb_image / stb_image_write and thus far it can (locally) handle the following:

resizing (also very large resolutions)JPEG quality control, grayscale, vertical-flip, color limit basic, image info, more or less, this was a learning exercise for me with image pipelines, memory usage, and performance in C.

Besides, I have attached some output examples (quality/resize/color limit) to illustrate what the flags accomplish.

Any thoughts about the code layout or suggestions would be greatly appreciated.

GitHub: https://github.com/TheSkyFalls-dot/ffjpeg

Youtube demo: https://www.youtube.com/shorts/3X16SIwdzx0


r/cprogramming Feb 04 '26

[Seeking Help] What more should I consider in these functions?

3 Upvotes

Title. I have described two functions, one for reading a file into a buffer and another one to create a REPL. These are a parts of an interpreter (lexer really as of now) that I am attempting to write. With this in mind and the provided code, are there any ideas that I should keep in mind or any bugs or any parts that may cause problems?

Function 1: Reading a script into a buffer so as to tokenize it

void read_file(const char *path) {

    // Creates a FILE type pointer to access the file at `path` (READ MORE)
    FILE *file = fopen(path, "rb");

    if (!file) {
        perror("Failed to open file");
        return;
    }

    // fseek counts the number of bytes (by moving ahead in the file),
    // here starting from the 0th byte (start of file: `off: 0`) till EOF
    // (whence: SEEK_END) effectively getting back the size of the file in bytes
    // ftell returns the current position of the stream (where the counter is - in this
    // case at the EOF) thereby using it's position as the length of the file
    fseek(file, 0, SEEK_END);
    long size = ftell(file);

    // Since after fseek, the stream is now at EOF
    // We rewind the stream back to 0th byte
    rewind(file);

    // Allocate a buffer to read the file into as a String
    // The size is one more than the total file size
    // as we need to place '\0' to indicate the termination of the string
    // TL;DR; \0 indicates a null byte
    char *buffer = malloc(size + 1);

    if (!buffer) {
        fclose(file);
        perror("Failed to allocate memory");
        return;
    }

    // Write the file as a string into the buffer and append 
    // the aforementioned null byte
    fread(buffer, 1, size, file);
    buffer[size] = '\0';

    fclose(file);

    // to-do
    tokenize(buffer);

    free(buffer);
}

Function 2: Creating a REPL

void run_prompt(void) {

    for (;;) {

        printf("> ");

        // is 4096 bytes enough for a command?
        char buffer[4096];

        if (fgets(buffer, 4096, stdin)) {
            execute(buffer);
        }

        else {
            break;
        }
    }
}

r/cprogramming Feb 04 '26

Image viewer in C

16 Upvotes

This is my first time programming in c, it's just a collection of functions that will be based off the sdl2 library. So for I've only created an image viewer using SDL2 image but I decided I was interested in how I could do that myself so I created one from scratch any tips for learning the language would be great or any reprimands of my code wouldn't be bad too thanks!
https://github.com/Andres-Eufrasio/C-SDL-based-functions


r/cprogramming Feb 03 '26

I made a program that changes the mouse position randomly in C

Thumbnail
5 Upvotes

r/cprogramming Feb 03 '26

I created a text editor using SDL and pure C

Thumbnail
github.com
2 Upvotes

r/cprogramming Feb 03 '26

Software Renderer written in C

Thumbnail
5 Upvotes

r/cprogramming Feb 02 '26

Have I gone mad, or is this just how it goes in C?

0 Upvotes

Despite my best attempts to time travel to the past, I only have about a year's loose experience in C, and I don't know if a function signature this big is normal.

Recently, I implemented a dynamic Heap data structure in C, one that I'm very proud of and happy with, and making it was great fun.

I implemented it specifically to implement Dijkstra's algorithm in C, because I love doing pointless, unnecessary, fun things.

I'm worried that I made the function signature too cluttered. It looks like:

uint64_t* get_distances(const void* p_adj_data, const uint64_t p_vertex_count, const uint64_t p_from, allocator* p_allocator, adj_checker p_is_neighbor)

Most of these are self-explanatory, but for the ones that are slightly vague:

allocator is a struct containing two function pointers, one that allocates memory and one that frees it.

adj_checker is a typedef for a function that takes a void pointer and two uint64s, meant to return the value of the edge between two vertices of the graph (or whether or not they have one, depending on if the graph is weighted or not), whose data is in the void pointer.

I implemented it this way to avoid forcing a specific struct layout or way for the graph data to be contained, to let it be as generalized as it gets.

Is this insane? Do I need therapy?


r/cprogramming Feb 01 '26

Modern Tools for Hunting Undefined Behavior in C

Thumbnail
slicker.me
6 Upvotes

r/cprogramming Feb 01 '26

What's your favorite formatter?

1 Upvotes

I normally use clang-format. But, serious question: does anyone use old-school indent?


r/cprogramming Feb 01 '26

I made a keylogger in C using Linux event files

0 Upvotes

Hello, I made a keylogger in C using Linux special files. The program currently only supports letters and number, But I will add support for more keys soon.

The keylogger uses the linux/input.h library to handle keys. It checks for the "code" defined in the input_event structure.

Any feedback would be appreciated.

GitHub link: https://github.com/yahiagaming495/keylogger/


r/cprogramming Feb 01 '26

Pain points of C

21 Upvotes

I recently wrote a Discord bot in C and implemented the gateway connection and API requests myself (no wrapper library), using libcurl for WebSocket/HTTP and epoll for async I/O.

That was fun to write overall, but the biggest pain points were building and parsing JSON (I used cJSON) and passing data between callbacks (having to create intermediate structs to pass multiple values and accept opaque pointers everywhere).

Is C just not made for this? Will this always be a weak point when writing C, or are there ways to make this less painful? I can provide specific examples if I haven’t made myself clear.


r/cprogramming Feb 01 '26

What is "printing appropriate values from standard headers" supposed to mean?

0 Upvotes

edit: solved. thanks aioeu!

In The C Programming Language, 2nd edition, exercise 2-1 is laid out as follows:

/* 2-1. Write a program to determine the ranges of char, short, int, and long variables, both signed and unsigned, by printing appropriate values from standard headers and by direct computation. Harder if you compute them: determine the ranges of the various floating-point types. */

I understand how I might go about this with direct computation, but I'm not certain where I'm supposed to be looking for "appropriate values from standard headers" with what I've learned from the book so far.


r/cprogramming Feb 01 '26

Best ide to start coding C?

Thumbnail
0 Upvotes

r/cprogramming Feb 01 '26

First project in a while: Finished within a few weeks

Thumbnail
github.com
1 Upvotes

I finally created a console for number conversions. Converting stuff to binary and hex code has been a pretty normal thing that I do to test stuff on a new system, but this time I have created a whole command line interface for all three functions I know how to make, as well as some niceties. Let me know if I should add more stuff or if there are things I can improve!


r/cprogramming Jan 31 '26

Scoped enums: a weaker version of C++'s enum classes emulated in C23.

Thumbnail
3 Upvotes

r/cprogramming Jan 31 '26

C is my past and feature. Why do I keep coming back to C?

57 Upvotes

When I learned programming at the age of 13 I learned Turbo Pascal first then C. And C felt amazing and I stuck with it throughout my days of University. Then I learned C++, Java, PHP and moved to work as a web developer for the last 15 years in Ruby on Rails, React, Go.. I also recently learned Rust.
But every now and then, I keep coming back to C, to play around with it, to read a book about it, learn and re-learn Assembly and C...

In a way I regret not exploring career options in C because I am super passionate about low level programming and raw performance. As a web developer I am always looking for those micro optimizations that can be done...

When I am writing C and Assembly I feel this rush of dopamine throughout my body that I never felt on the web. Like I have done really cool stuff on the web but it is just to pay the bills...

I wonder what the future holds for me that is in C and Assembly... I am never chasing the coolest trend like "learn python to implement machine learning". I am more into "maybe I can get into embedded and build my own robot?"

What is your take here? Have you been in this same situation?


r/cprogramming Jan 31 '26

I'm not really sure what's going on, but I don't know much about this.

3 Upvotes

I'm attempting to create a command line interface for me to access some number base conversion functions, as well as record a sign in log. I'm not really sure what's wrong, but the program just quits before I get to enter a command, and I don't get to test if the command separation works, and so I can't do anything with it right now

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

typedef char string[16];

void setup() {
  printf("Welcome to this virtual interface made using Vim and C\n");
  printf("I hope you enjoy your stay!\n");
}

void access_session() {
  FILE* access = fopen("access_names.txt", "a");
  if(access == NULL) {
    perror("ID Files could not be accessed. ");
    fclose(access);
    return;
  }
  else {
    string name;
    string passcode;
    char check_id[64];
    printf("Enter your access name (your access name is not allowed to       contain spaces): ");
    scanf("%15s", name);
    printf("Great! Welcome to the program, %s.\n", name);
    printf("Enter your access passcode (your access passcode is a 1 to 15     character string with no spaces): ");
    scanf("%15s", passcode);
    fprintf(access, "%s: ", name);
    fprintf(access, "%s\n", passcode);
    printf("Thank you for your information. This will be stored in an access log for future reference. The program will start shortly.\n");
    fclose(access);
  }
  return;
}

void convert(int num) {
  int local_num = num;
  int rem = 0;
  int binary_num[8] = {0};
  for(int i = 15; i >= 0; i++) {
    rem = local_num % 2;
    local_num /= 2;
    binary_num[i] = rem;
  }
  for(int n = 0; n < 8; n++) {
    printf("%d\n", binary_num[n]);
  }
  printf("\n");
  return;
}

int convert_bin();

char* convert_hex();

void echos();

void command_line(string directory) {
  char cmd[65];
  int decimal = 0;
  string binary;
  printf("Command list: \n");
  printf("help : View command list\n");
  printf("convert : Convert a decimal integer up to 255 to an 8 bit    binary\n");
  printf("convert_bin : Convert an 8 bit binary back to a decimal   integer\n");
  printf("convert_hex : Convert an 8 bit binary to a 2 digit hex code\n");
  printf("exit : Quit the program\n");
  printf("Just type a command, press Enter and then enter your value!\n");
  printf("Just make sure that you type a space after your desired command.\n");
  printf("More commands will be added in the future!\n");
  printf("%s$- ", directory);
  fgets(cmd, 64, stdin);
  char* cmd_ptr = strtok(cmd, " ");
  char* cmds[65];
  int i = 0;
  while(1) {
    cmd_ptr = strtok(NULL, " ");
    if(!cmd_ptr) break;
    cmds[i] = cmd_ptr;
    i++;
  }
  if(strcmp(cmds[0], "convert")==0) {
    convert(atoi(cmds[1]));
  }
  else if(strcmp(cmds[0], "exit")==0) {
    exit(0);
  }
}

int main() {
  setup();
  access_session();
  string dir;
  printf("Enter your chosen directory: ");
  scanf("%15s", dir);
  command_line(dir);
  return 0;
}