r/cprogramming • u/Successful_Catch9563 • 5m ago
How can i start c language
I am not a complete beginner. I have some knowledge later i stopped due to some reasons now i want to start please give some advice.
r/cprogramming • u/Successful_Catch9563 • 5m ago
I am not a complete beginner. I have some knowledge later i stopped due to some reasons now i want to start please give some advice.
r/cprogramming • u/__Hawkly__ • 18h ago
I am in the first semester of university and I have to take a C programming Class. the first test is in about 2 1/2 weeks and I just cant understand C for the life of me.(Its a first of two chances but still,It'd be great to have less worries in January/February)
I had fallen behind due to the fact the class moved very quickly since basically everyone already knew how to code and having to shift my focus for math tests.
I dont even know why, I just go blank once I see the empty page infront of me. I know which loops i should use when--technically-- and the datatyps for the most but from Arrays on It just didn't click anymore for some reason.
I know this sounds pathetic and Im not sure if this is the right place to ask but Is there any way to like get yourself to finally absorb the syntax and stuff?
I always get told its "just practice,keep coding stuff and make yourself easy programs and build from there" but then after I look at the assignments i was given and it feels like i studied 2+2=4 for a Real Analysis exam.
Are there any Books,videos, anything I could binge?
I always see how people "Learn C in only Xy hours" online but cant find any media that makes that seem humanly possible.
Any help is appreciated,thanks!
r/cprogramming • u/Mainak1224x • 14h ago
I’ve been working on flint, a lightweight, Git-native C/C++ build system and package manager written in pure C. Just shipped a new update that adds a native test engine so you don't need extra build scripts or external runners just to compile and run unit tests.
How it works:
Drop your C/C++ test files into a tests/ directory and prefix them with test_ (e.g., test_math.c, test_parser.cpp).
Run flint test to automatically discover, compile, and execute each test file one by one.
Standard executable and library builds automatically ignore tests/test_*, keeping production builds clean without manual exclusions.
my-project/
src/
main.c
tests/
test_math.c
test_utils.cpp
Repo: https://github.com/mainak55512/flint
r/cprogramming • u/Bratan_Corporation • 23h ago
I maintain CLAP, an open-source command-line frontend for C and C++. The use case is a small C program on a fresh Windows machine. With Python installed, you can install CLAP with `python -m pip install clap-compiler` and build a local `main.c` with `clap build main.c -o hello`. If needed, CLAP downloads a pinned Zig/Clang toolchain on the first build. It also supports multi-file projects and CMake.
I’d like feedback from people who teach or learn C on Windows. What would you expect a tool like this to show when the first build fails, and what would make the compiler setup easier to understand?
Source and examples (MIT): https://github.com/BRATAN-CORP/clap
r/cprogramming • u/NazgulResebo • 1d ago
I follow these steps:
Source code:
https://github.com/FractalCodeRicardo/zen-programming/tree/main/kaleidoscope
C part
#include <raylib.h>
#define size 800
float time = 0.0;
int main() {
InitWindow(size, size, "Kaleidoscope");
Shader shader = LoadShader(0, "kaleidoscope.glsl");
int timeLoc = GetShaderLocation(shader, "time");
while(!WindowShouldClose()) {
time = GetTime();
SetShaderValue(shader, timeLoc, &time, SHADER_UNIFORM_FLOAT);
BeginDrawing();
ClearBackground(BLACK);
BeginShaderMode(shader);
DrawRectangle(0, 0, size, size, BLACK);
EndShaderMode();
EndDrawing();
}
CloseWindow();
}Shader part
#version 330
out vec4 color;
uniform float time;
vec3 palette(float t) {
vec3 a = vec3(0.5, 0.5, 0.5);
vec3 b = vec3(0.5, 0.5, 0.5);
vec3 c = vec3(1, 1, 1);
vec3 d = vec3(0.0, 0.33, 0.67);
return a + b*cos( 6.283185*(c*t+d) );
}
void main() {
float pi = 3.1416;
vec2 uv = gl_FragCoord.xy / 800;
uv = uv - 0.5;
float angle = atan(uv.y, uv.x) * time * 0.3;
float radius = length(uv);
float slices = 3;
float size = pi * 2 / slices;
float internal_angle = mod(angle, size);
internal_angle = abs(internal_angle - size /2.0);
vec2 internal_point= radius *
vec2(
cos(internal_angle) * radius,
sin(internal_angle) * radius
);
float pattern =
sin(internal_point.x * time *10 * 0.5) *
sin(internal_point.y * time *10 * 0.5);
vec3 c = palette(pattern + time * 0.5);
color = vec4(c, 1);
}r/cprogramming • u/EqualTumbleweed512 • 1d ago
I heard that `-fsanitize` flag can detect memory errors so I used it with on my project. `-fsanitize=address,undefined`, but when I looked in my system monitor, I saw that the the memory it used kept increasing.
I reviewed my code to see if the code had any memory leaks, but it didn't.
I compiled the project without that flag and now the memory usage didn't increase and it used only half the memory it used with the flags, which is fair
Is this common behavior?
r/cprogramming • u/FransFaase • 1d ago
Advent of Code is an interesting way to test your C programming skills. Every day there will be a puzzle consisting of two parts, where the first part is usually easier than the second part.
r/cprogramming • u/Rayman_666 • 2d ago
I like programming, doing maths with memory allocation and being crazy for 1kb in my programs. I like C and created projects with it. I like calloc malloc, and sizeof more than my peace of mind.
I wanted to start systems programming, but can't find good starting point and resources anywhere(yt and google is empty). I don't like read books with 500p pages. I am a teen. But, I know my stuff.
I have experience with high languages, C, using linux and sql too.
Any way I can start systems programming with understand and starting points.
Not a member of tutorial hell, proof,
r/cprogramming • u/NazgulResebo • 3d ago
I created a simple moiré fractal using C, raylib and GLSL shaders.
The idea is quite simple: start with two nearby centers and generate concentric circles around each one, gradually increasing their radius.
Then, using the radius as input to a sin function, I generate alternating light and dark values. By applying this to the colors, the two circle patterns interact and produce the characteristic moiré effect.
Complete coding session:
Source code:
https://github.com/FractalCodeRicardo/hangover-programming/tree/main/moire-shaders
C / Raylib
#include <raylib.h>
#define size 800
float time = 0.0;
int main() {
InitWindow(size, size, "Moire Circles");
Shader shader = LoadShader(0, "moire.glsl");
int timeLoc = GetShaderLocation(shader, "time");
while (!WindowShouldClose()) {
time = GetTime();
SetShaderValue(shader, timeLoc, &time, SHADER_UNIFORM_FLOAT);
BeginDrawing();
BeginShaderMode(shader);
DrawRectangle(0, 0, size, size, BLACK);
EndShaderMode();
EndDrawing();
}
CloseWindow();
}
Glsl
#version 330
out vec4 color;
uniform float time;
void main() {
vec2 uv = gl_FragCoord.xy / 800;
uv = uv - 0.5;
float a = 30;
vec2 center1 = vec2(0.1, 0.0);
vec2 center2 = vec2(-0.1, 0.0);
float d1 = distance(center1, uv);
float d2 = distance(center2, uv);
vec4 color1 = vec4(
0.0 * sin(a * time*d1),
0.8 * sin(a * time*d1),
0.8 * sin(a * time*d1),
1
);
vec4 color2 = vec4(
1 * sin(a * time*d2),
0.2 * sin(a * time*d2),
1 * sin(a * time*d2),
1
);
color = mix(color1, color2, 0.5);
}AI Disclaimer:
I did not use AI to code the fractal.
r/cprogramming • u/gumnos • 3d ago
Working with a file-format that has include directives (effectively inlining the referenced file), my plan has been to have lex push/pop the top FILE* into a stack, open the included-file, set it to yyin to that new FILE*, continue lexing based on that new file (effectively recursing into any included files there), then close the included file, pop the original file's FILE* off the stack, and resume where it left off.
However, I have concerns whether monkeying with yyin like this is something that can be done portably, especially if lex implementations buffer the content read from the file (meaning that changing the yyin might not impact the next characters/tokens because they're already buffered, meaning lex sees the buffered next tokens from the first file rather than the tokens from the new/included file, which I understand flex might do). Similarly pushing items back (ungetc()/unput()) after an include directive might result in enqueuing a character from the including-file where I really want the next characters to come from the included-file.
Are there best practices for reliably switching the input streams provided to lex?
FWIW, the dev environment is FreeBSD/OpenBDS with their implementations of lex, not GNU flex out of the gate.
r/cprogramming • u/AKJ7 • 3d ago
Hello!
I’ve been working on cortex (cx), a C/C++ package manager and build tool inspired by Rust’s Cargo and Python’s uv, and I’d love to share it with you and get some feedback.
Setting up a C++ project with clean dependency management, lockfiles, features, and workspaces often requires gluing together multiple tools and boilerplate CMakeLists.txt files. With cx, you describe your package in a single cx.toml file, it resolves and locks dependencies, generates the underlying CMake project, and drives the build automatically.
Zero-boilerplate builds: Sources, tests, benchmarks, and examples are discovered by convention (src, tests, benches, examples). Supports mixed C (C90–C23) and C++ (C++98–C++26), including C++20 modules (.cppm, .ixx).
Flexible dependency management: Pull dependencies from registries, Git repos, local paths, system packages (find_package), or vcpkg. Any existing CMake, Autotools, or SCons project works out of the box as a Git or path dependency.
PubGrub version resolution & lockfiles: Uses the PubGrub solver (like uv and pub) for clear conflict explanations, and pins exact versions, Git commits, and SHA-256 hashes in cx.lock.
Cargo-style features & workspaces: Supports optional dependencies, feature flags (exposed via CX_FEATURE_ macros), and multi-package workspaces sharing a single lockfile and target/ directory.
Built-in developer workflows: Comes with cx test, cx bench, cx fmt (clang-format), cx lint (clang-tidy), cx doc (Doxygen), cx vendor for offline builds, and built-in sanitizer/LTO build profiles.
IDE & CI friendly: Generates standard CMake projects (cx generate) and JSON metadata (cx metadata) so your existing IDE setup works seamlessly, plus --locked and --offline flags for CI.
First Release & Self-Hosting: This is the very first release. Right now the repo still includes its bootstrapping CMake files, which will be removed in the next release now that cx can build itself.
OS Support: Works on Linux and macOS. Windows (MSVC) support is newly added and passing in CI, though it hasn't been battle-tested in the wild yet.
Public Registry: There isn't a central public registry yet, though cx works directly with Git repositories, local paths, vcpkg, system packages, and includes a lightweight self-hosted registry server (cx-registry).
You can install prebuilt binaries via the install script in the README or build it from source with CMake 3.28+ and a C++23 compiler.
I’d really appreciate any feedback, bug reports, or thoughts on what would make this genuinely useful for your C/C++ workflows!
Thanks
r/cprogramming • u/codedeco • 3d ago
I know c fundamental, and understanding other things
r/cprogramming • u/Avi250 • 4d ago
Hello, everyone. This is a school project so I'm not allowed to share my code, but it shouldn't be a big problem since my question is more...general.
In my programs I have several semops and msgops. I had to change my SIGTERM's handler and, with what I've been told (here, too) and I've read, I only put a flag variable in it, which I'll have to check continuously on. I have managed to find a way around if my msgops get interrupted, however, the main problem would have been my processes waiting on a semop or message that would never come (signal comes right before the syscall, it changes the variable and returns, main program continues where it left off).
I figured I'd have the processes enter loops where they wait on the syscall and, if the time allocated runs out, it checks the flag variable. If it's been changed, it proceeds a certain way; otherwise, the loop continues.
It's important to say that SIGTERM will always be sent to all my processes after the right amount of time has passed.
Is this good practice? Or a bad workaround to my problem? In case it is good practice: the simulation can last for about 8 minutes, while the processes usually work with nanoseconds (sometimes seconds). Is it ok to have the processes check for said variable every 2-5 seconds? The processes will be taking note of the waiting time. My main goals here are to avoid active waiting and increase concurrency between processes.
Thank you in advance!
Edit: I'm sorry, I should have specified we're only allowed to use SystemV IPC
r/cprogramming • u/Mrazik19 • 5d ago
r/cprogramming
•
•
6d ago
Hey guys! So, I'm a masochist, and when I saw that fantasy consoles like pico 8 use... Lua <eugh>, I decided to make my own infinitely worse version. It definitely segfaults on some edge cases, the assembly isn't perfect or even great, and it only works on linux (maybe all posix?) And that too with a jank build script.
Would appreciate feedback!
r/cprogramming • u/DerpKidSavage • 6d ago
r/cprogramming • u/Stunning_Gas_3862 • 6d ago
r/cprogramming • u/NazgulResebo • 7d ago
In this video, I code a Dragon Curve fractal using C and Raylib.
The approach is quite simple:
I take the last point as a pivot, then rotate the remaining points 90 degrees around it. Finally, I connect the new points to create the next iteration of the fractal.
Source code:
https://github.com/FractalCodeRicardo/zen-programming/blob/main/dragon-curve/dragon.c
#include <stdio.h>
#include <raylib.h>
#include <raymath.h>
#define linesSize 90000
#define lineSize 2
typedef struct {
Vector2 p1;
Vector2 p2;
} Line;
void DrawLines(Line lines[], int s) {
for(int i = 0; i < s; i++) {
Line l = lines[i];
DrawLine(l.p1.x, l.p1.y, l.p2.x, l.p2.y, WHITE);
}
}
Vector2 rotate(Vector2 p, Vector2 rp) {
Vector2 d = Vector2Subtract(p, rp);
Vector2 r = Vector2Add(rp, (Vector2) {-d.y, d.x});
return r;
}
int AddLines(Line lines[], int s) {
if (s * 2 >= linesSize)
return s;
Vector2 rp = lines[s-1].p2;
int newSize = s - 1;
for(int i = s -1; i >= 0; i--) {
Line l = lines[i];
Vector2 p1 = rotate(l.p1, rp);
Vector2 p2 = rotate(l.p2, rp);
newSize++;
lines[newSize] = (Line) { p2, p1};
}
return newSize + 1;
}
int main() {
Line lines[linesSize];
int s = 1;
float center = 900 / 2.0;
lines[0] = (Line) {
(Vector2) { center, center},
(Vector2) { center + lineSize, center},
};
InitWindow(1500, 900, "Dragon curve");
while(!WindowShouldClose()) {
BeginDrawing();
ClearBackground(BLACK);
if (IsKeyPressed(KEY_SPACE)) {
s = AddLines(lines, s);
}
DrawLines(lines, s);
EndDrawing();
}
CloseWindow();
}r/cprogramming • u/_EHLO • 7d ago
A general-purpose, header-only C99 library for Unix-like systems, implementing a disk-based, dynamically resizable, fixed-slot, (open-addressed) hash table with Fibonacci hashing (Knuth's multiplicative method), triangular probing, per-home-slot probe-bound metadata (with additional early-exit logic), partial in-place value updates (without relocating entries) and incremental rehashing, all designed for modern extent-based filesystems.
Hello fellow reddit users. Feel free to AMA about it.
r/cprogramming • u/fleaspoon • 8d ago
Seven years ago I decided to learn how to make a game from scratch in C and last week I finally released it.
When I started the project I wanted to write as much as possible myself from scratch. In the end that included the game engine, a Vulkan renderer, the level editor, asset pipeline and the build system. The codebase is in C style but I use the C++ compiler so I can use operator overloading for math. I don't use the standard library, exceptions or OOP.
Initially I was using CMake but I found it quite painful to work with. Whenever I wanted to update the setup of my build I had to go back to a different language and deal with something that often felt like a hack and kept breaking.
Because of this I decided to build my own tool. The build system ended up being a small program written in the same style as the rest of the game, using the same header only base library. In essence it just calls clang directly and the setup of the project is a simple fat struct.
On each run every source file gets hashed and it gets compared against the hashes from the previous build. Each source file has a saved entry in a cache that also includes the exact compiler command, so changing a flag will rebuild everything influenced by it.
Also clang generates a dependency file for every source file that lists the headers it includes. If any of those headers change, that source gets recompiled. Everything compiles in parallel and the linker only runs when something has actually been rebuilt.
This approach doesn't require having a separate configuration language or generated project files like CMake. Building only requires clang and since the build tool is just simple code, it can be debugged like the game itself. Thanks to all this adding shader compilation, bundling and code signing was quite simple. I tried doing that with CMake but I just couldn't figure out how to make it work properly.
The game I built with these tools is called Satelital. It's a 2D space puzzle game about exploring alien worlds and figuring out how their rules work. There are no explicit explanations of the puzzle rules. Instead, you gradually build up your understanding of how the world works and use that knowledge to solve new puzzles.
If you're interested in the technical side of building a game engine from scratch, I also wrote an article about it on my blog:
https://spectralorbit.com/blog/satelital_game_engine
And the game is available on Steam with a free demo:
https://store.steampowered.com/app/3256790/Satelital/
r/cprogramming • u/Opening_Can_3656 • 7d ago
Hey everyone,
I’ve been working on Keen, a language that gives C a modern, Rust-inspired syntax and Cargo-like tooling without changing C’s underlying semantics.
Keen changes C’s syntax only. There is no borrow checker, no type checker, and no safety enforcement. All of C’s rules (integer promotion, ABI, linkage, UB) remain completely intact. Keen transpiles .kn files to C, hands them off to gcc or clang for semantic checking and compilation, and maps compiler diagnostics directly back to your .kn source lines via #line directives.
It's aimed at C developers who want modern ergonomics (modules, match, for i in 0..n, no header boilerplate, built-in testing/formatting) without giving up C's simplicity, or C devs looking to get comfortable with Rust's syntax before tackling the borrow checker.
use <stdio.h>;
struct Point { x: f32, y: f32 }
impl Point {
pub fn len2(p: *const Point) -> f32 { p->x * p->x + p->y * p->y }
}
pub fn main() -> i32 {
let p = Point { x: 3.0, y: 4.0 };
printf("%.1f\n", Point::len2(&p) as f64);
return 0;
}whet + keen): Includes keen new, incremental keen build, keen run, keen fmt (comment-preserving, idempotent), and keen test (runs #[test] functions in isolated processes).#include via use <stdio.h>;, drop down to raw C anytime with c!("..."), link existing .c/.o/.a files, or use keen emit --split to generate clean .h/.c files for existing C projects.pub handles external linkage while everything else defaults to static.GitHub: https://github.com/romishalom/keen
I'd love to hear your thoughts on the syntax mapping, edge cases with C interop, or what features you'd want to see next!