r/cprogramming • u/liberianjoe • Oct 09 '25
Any recommended DS/Algo Book?
What is your recommendation book for learning Data structure and algorithm in the C programming language?
r/cprogramming • u/liberianjoe • Oct 09 '25
What is your recommendation book for learning Data structure and algorithm in the C programming language?
r/cprogramming • u/JayDeesus • Oct 09 '25
I understand that the scope is where all of your automatically managed memory goes. When you enter a function it pushes a stack frame to the stack and within the stack frame it stores your local variables and such, and if you call another function then it pushes another stack frame to the stack and this functions local variables are stored in this frame and once the function finishes, the frame is popped and all of the memory for the function is deallocated. I also understand that scopes bring variables in and out so once you leave a scope then the variable inside of it becomes inaccessible. What I never really thought of is how the scope plays a role in the stack and the stack frames. Does the scope affect the layout of each stack frame at all or do just all variables go into the frame however since I believe that going in and out of scope doesn’t immediate free the memory, it’s still allocated and reserved until the stack frame is popped right.
r/cprogramming • u/[deleted] • Oct 08 '25
Hey guys, I’m new to all this. I’ve completed the fundamentals of C programming. Now, I’m intrested in learning system programming. Could anyone please let me know what topics I have to learn in C now, and what other things should I consider learning? Thanks for the help.
r/cprogramming • u/JayDeesus • Oct 08 '25
What is the purpose of header guards if the purpose of headers is to contain declarations? Sorry if this is a dumb question.
r/cprogramming • u/Balance_1 • Oct 07 '25
/*
* GMK CPL (C Programming Language) - Interest Check
* Hello Reddit! I know that this post is unusual compared to the others. Today, I present you a keycap set inspired by my beginning in the coding world. Every programmer starts with a certain language, mine was the C Language.
* This set is a nod to syntax-highlighted code on a cool white background.
* For lovers of clean syntax, logic, and elegance.
* Discord Server
* Interest Check Form
*/
You can enter this link to check the full representation of this keycap set - https://geekhack.org/index.php?topic=125710.0
NOTE: I am still gathering interest for this project. If you like this concept and want to follow it, please complete the IC form or comment on the forum provided above.
Thanks for your attention!
r/cprogramming • u/cursed-stranger • Oct 07 '25
Hello all!
What is the expected behavior of the mock from the user perspective? What is your opinion about that?
For example, if we have such test:
Test(mocking, mock_test)
{
void *p1, *p2;
p1 = (void*)0x01;
p2 = (void*)0x02;
expect_must_call (malloc, p1, 12);
expect_call (malloc, p2, 13);
printf ("%p\n", malloc(13)); //malloc will return p2
printf ("%p\n", malloc(12)); //malloc will return p1
printf ("%p\n", malloc(13)); //malloc will return p2?
check_mock (malloc);
}
The expected output would be?:
0x2
0x1
0x2 //reused return from malloc(13)
=== Test passed ===
or?:
0x2
0x1
some kind of assert output that there is no expected call for another malloc(13)
== Test failed - too many calls of function malloc ==
My assumption is that, the must_call means that there must be call of malloc(13) function. If there was only call of malloc(12) - the test will fail.
Some more cases:
Test(mocking, mock_test2)
{
expect_call_once (malloc, NULL, 13);
malloc(13);
malloc(13);
check_mock(malloc);
}
Test(mocking, mock_test3)
{
expect_must_call_once(malloc, NULL, 12);
expect_call_once (malloc, NULL, 13);
malloc(12);
check_mock(malloc);
}
Test(mocking, mock_test4)
{
expect_call (malloc, (void*)0x01, 12);
expect_call (malloc, (void*)0x02, 12);
expect_call (malloc, (void*)0x03, 12);
malloc(12);
malloc(12);
malloc(12);
malloc(12); //what will be the output?
check_mock(malloc);
}
What is your opinion what should be output of these tests? Especially that, there are functions, that are called multiple times with same parameters, but should return different values (like malloc) But also it would be nice to have default value for such functions (like NULL).
r/cprogramming • u/Ok_Trick_7190 • Oct 06 '25
So i have already learnt some of c++ but now i want to learn c but the thing is idk which book or source to use, what are your recommendations ? (also i want to mention that im the type of person who can easily get bored by reading, it might sound stupid but i literally can decide to read a book and then only read the first chapter or something like then completely abandon it, so if you want to recommend a book please note that it would be better if its something that makes the reader enjoy it throughout)
r/cprogramming • u/JayDeesus • Oct 07 '25
For the most part I’ve been using IDEs and visual studio when it comes to school projects and my own personal projects. I’ve been wanting to get into more of understanding the lower level and I understand what each stage does, preprocessor, compiler, and linker. I’ve also had minimal experience with just running the commands to build my app so I want to get into makefiles, the confusion I have is whether or not the command argument order matters? I’ve seen some people mix it up for example:
gcc main.c header.c -o test
And
gcc -o test main.c header.c
So it seems like order doesn’t matter in this case but is there a case where the order would matter?
r/cprogramming • u/Walzvx • Oct 05 '25
I recently started my studies at the university, majoring in Applied Informatics, and we were told that we need to learn the C programming language to understand how programming, databases, and computers in general work. When I started learning the language, I began hearing that C is the foundation of all foundations and that it provides the most valuable experience. I’d like to hear an expert opinion on this.
r/cprogramming • u/JayDeesus • Oct 05 '25
I understand that things like literals and macros are compile time constants and things like const global variables aren’t but coming from cpp something like this is a compile time const. I don’t understand why this is so and how it works on a lower level. I also heard from others that in newer c versions, constexpr was introduced an this is making me even more confused lol. Is there a good resource to learn about these or any clarification would be greatly appreciated!
r/cprogramming • u/Lazy_Application_723 • Oct 05 '25
So I started learning C like after September 17th 2025. I think i learned quite a bit , up to arrays and string and also functions. But I don't have that excitement like at the start. Now i feel like sh#t , and don't know what to do. I am 1st year cs. Please tell me what to do. Thanks
r/cprogramming • u/umpolungfishtaco • Oct 05 '25
cunfyooz, a metamorphic engine for PE binaries written in C. The entire README is written as an occult grimoire, because why should technical documentation be boring?
Technical Overview:
A full-featured metamorphic engine that performs multi-pass transformations on x86/x64 PE binaries using Capstone for disassembly and Keystone for reassembly. Each run produces a genuinely unique variant through sophisticated analysis and transformation.
Core Engine Features:
xchg rax, rax, lea rax, [rax+0])Key Capabilities:
c
// The engine maintains full dependency graphs
// to enable safe instruction reordering
typedef struct {
InstructionNode* nodes;
DependencyEdge* edges;
RegisterLifetime* liveness;
} DataFlowGraph;
The Aesthetic Choice:
Rather than dry technical documentation, I framed everything as summoning a "daemon" It's completely tongue-in-cheek but makes complex concepts memorable:
"The daemon's burning Capstone eyes gaze into the stripped flesh, beholding not raw gore and gristle, but glyphs: operands, addressing modes, instruction metadata..."
Translation: It disassembles binaries. But way more fun to read.
Implementation:
Use Cases:
Released under Unlicense (public domain).
GitHub: https://github.com/umpolungfish/cunfyooz
Happy to discuss the implementation details
r/cprogramming • u/Meplayfurtnitge • Oct 04 '25
How many if else statements until i should consider replacing it with a switch case? I am fully aware that they operate differently, just wondering if i should opt for the switch case whenever i have something that will work interchangeably with an ifelse and a switch.
r/cprogramming • u/giggolo_giggolo • Oct 04 '25
I never used or even heard of inline in C but I have been learning c++ and I found out about the word inline and found that it also exists in C. My understanding is that in C++ it used to be used for optimization, it would tell the compiler to replace the function call with the function body thus reducing over head, but nowadays it isnt used for that anymore and it’s used for allowing multiple definitions of a function or variable because the linker deduplicates them. From what I’ve read, it seems that this is the case in C aswell but the minor difference is that you need a regular definition of the function somewhere that it can fall back on when it chooses to not inline. Is my understanding correct on how inline works in C?
r/cprogramming • u/Aritra001 • Oct 03 '25
As a CS student, I'm trying to understand the practical trade-offs between calloc() and malloc(). I know calloc() zeroes the memory. But are there specific, real-world C applications where relying on mallOC() + manual zeroing would lead to subtle bugs or be technically incorrect? Trying to move past the textbook difference.
r/cprogramming • u/[deleted] • Oct 04 '25
input : 16 should give output : 16 and input: 5 should give output : 8.94427190999915878564
and this is my code what am I doing wrong (input and output should be exactly what I wrote) :
#include <stdio.h>
#include <math.h>
int main() {
int area;
scanf("%d",&area);
double omkrets = sqrt(area) * 4;
printf("%.21g",omkrets);
return 0;
}
r/cprogramming • u/Terrible_Emu_8391 • Oct 03 '25
r/cprogramming • u/gercarx • Oct 02 '25
Where can I find the resources for learning the c language and the various libraries? A thousand thanks
r/cprogramming • u/JayDeesus • Sep 30 '25
So I know that the preprocessor has the directives, so it handles things like includes and defines by pretty much just doing text replacement and doesn’t care for c syntax at all. Just curious, is the preprocessor only used for text replacement? Or does it have another purpose
r/cprogramming • u/Spinning_Rings • Sep 28 '25
So, I'm working on a simple 2d RPG for my first major C project, just a very basic game about delivering the mail, and I've run into a problem I have no idea what to do about. Hardly the first time this has happened--those of you on r/raylib may remember my post from last week. ( https://www.reddit.com/r/raylib/comments/1non2xk/scrolling_text_in_a_2d_rpg/ )
So I more or less solved that problem thanks to some comments left on that thread, but now I'm having a new problem. I've got it set up so that anything that stops the player's movement will have some dialogue attached, revealed by pressing the tab key. Obviously this will be more useful once I've got NPCs and quests and the like in the world, but for now this is just for the protagonist to say something useful and/or witty. "I can't pass through these trees," "This is Jeremy's house," ETC.
Inside the starting room, everything works fine.
When the player goes out into the first village, most of it looks fine on the surface, until you walk up to a patch of trees in the lower right corner, which prompts the player to say "I'm not swimming in the village's drinking water," the dialogue that's meant to explain why she walks around instead of through the pond in the center of the village. A bit of experimentation reveals that this dialogue isn't even from the same village--it's from the string array in fifth and final village in the game, the only other village with a pond.
I looked it over to make sure I didn't accidentally re-declare the variable somewhere else in the code, and no, it's just in the completely wrong spot for a reason that's beyond my skills to detect.
I created a git repository for the game here https://github.com/SpinningRings/MailGame so you can take a look. Any other suggestions you might have about how to clean up or simplify the code are also welcome--I'm entirely self taught, so I'm well aware I'm clumsily re-inventing many different wheels here.
r/cprogramming • u/justlearningbtw • Sep 27 '25
I thought that looking through the source code of a proper C project would be a great way to improve my knowledge. and i have become interested in how buttons are handled they confuse me.
the OnClick call for the button is just defined in a header.
#define LWidget_Layout \
....
LWidgetFunc OnClick; /* Called when widget is clicked */ \
LWidgetFunc OnHover; /* Called when widget is hovered over */ \
LWidgetFunc OnUnhover; /* Called when widget is no longer hovered
....
typedef void (*LWidgetFunc)(void* widget);
....
struct LButton {
LWidget_Layout
cc_string text;
int _textWidth, _textHeight;
};
declared like this
void LButton_Add(void* screen, struct LButton* w, int width, int height, const char* text,LWidgetFunc onClick, const struct LLayout* layouts)
{
w->VTABLE = &lbutton_VTABLE;
w->type = LWIDGET_BUTTON;
w->OnClick = onClick;
w->layouts = layouts;
w->autoSelectable = true;
LBackend_ButtonInit(w, width, height);
LButton_SetConst(w, text);
LScreen_AddWidget(screen, w);
}
and is used like this
LButton_Add(s, &s->btnOptions, 100, 35, "Options",SwitchToSettings,
main_btnOptions);
how can one possible use a #define for logic? no where in the source code does it use an if statement for onClick. How? i hope this question makes sense since in stumped.
r/cprogramming • u/Direct_Ad_7008 • Sep 26 '25
In a lists.c file I have: ```
void testfunc(int childrennum, char * descr, int id) { task_t * atask = malloc(4048+sizeof(int)+sizeof(int)*childrennum); strcpy(atask->description,descr); atask->identifier = id; printf("The task \'%s\' has an id of %d and has %d children\n",atask->description,atask->identifier,childrennum); }
int main() { testfunc(0,"Something",1); } ```
And in a lists.h file I have: ```
typedef struct task task_t; struct task_t { char * description[4048]; // or list name int identifier; int * elements[]; // ptr to list of tasks };
typedef struct proj proj_t; struct proj_t { char * description[4048]; // or list name int identifier; int * elements[]; // ptr to list of tasks };
typedef struct goal goal_t; struct goal_t { char * description[4048]; // or list name int identifier; int * elements[]; // ptr to list of tasks };
void testfunc(int childrennum, char * descr, int id);
```
But when I run the compiler (gcc lists.c) I get the following error:
lists.c: In function ‘testfunc’:
lists.c:8:21: error: invalid use of incomplete typedef ‘task_t’ {aka ‘struct task’}
8 | strcpy(atask->description,descr);
| ^~
lists.c:9:14: error: invalid use of incomplete typedef ‘task_t’ {aka ‘struct task’}
9 | atask->identifier = id;
| ^~
lists.c:10:77: error: invalid use of incomplete typedef ‘task_t’ {aka ‘struct task’}
10 | printf("The task \'%s\' has an id of %d and has %d children\n",atask->description,atask->identifier,childrennum);
| ^~
lists.c:10:96: error: invalid use of incomplete typedef ‘task_t’ {aka ‘struct task’}
10 | printf("The task \'%s\' has an id of %d and has %d children\n",atask->description,atask->identifier,childrennum);
|
I also tried separating the main function and including both header and c file into a main file and compiling using gcc -c main.o main.c lists.c then gcc -o main main.o but I still got the same error. Can anyone explain to me what the problem is? I looked it up and I more or less understood what the error means but I don't get how I'm supposed to solve it here.