October 22, 2024
Chicago 12, Melborne City, USA
C#

How to Prevent Blank Lines and Remove Extra Spaces in C Word-per-Line Output?

I’m reading K&R’s The C Programming Language and currently working on Exercise 1-12. The issue I’m facing isn’t with completing the exercise itself, but with fixing a bug that has come up as a result of my code. The code produces an unwanted blank line when encountering two or more spaces. I want to ensure

Read More
C#

Deadlock Issue in Dining Philosophers Problem with Multithreading in C

I am currently working on a solution for the Dining Philosophers problem in C, using multithreading with pthreads. The objective is to simulate philosophers who alternately eat and think, using forks that are shared among them. However, I’m encountering a potential deadlock issue, which I cannot seem to resolve. Problem Description: When running the program

Read More
C#

How to print a value stored in a variable in C

How to print a value stored in a variable in C. I am new in C and I have a little bit of experience in python. In python if we take num = 30 and if we do print(num). the output is 30. I want to do the same thing in c but if i

Read More
C#

AVR Microcontroller Blinking LED Not Working

I am trying to learn embedded electronics using the 8-bit AVR microcontroller and whilst I have experience with electronics and programming I am a noob with embedded systems. The chip I am trying to program is the Atmega168. I am following the Make: AVR Programming book but I am at a complete loss trying to

Read More
C#

Check if the file was opened in C

I am trying to write a function to check if the file has been opened and if not, open it. The file is defined in main and is passed to the function as an argument. The code works, but when I try to add something to main function (as simple as int i;), the program

Read More
C#

Can KMDF driver check if an IOCTL came from an admin user-mode process?

I’m playing with a KMDF (kernel mode) sample driver that came with VS 2022. I’ve added the following code to process IOCTL in my Queue.c: VOID TestEvtIoDeviceControl( _In_ WDFQUEUE Queue, _In_ WDFREQUEST Request, _In_ size_t OutputBufferLength, _In_ size_t InputBufferLength, _In_ ULONG IoControlCode ) { NTSTATUS status = STATUS_SUCCESS; if(IoControlCode == IOCTL_MY_TEST) { REQ_TEST* pReq =

Read More
C#

Unable to access dynamically allocated struct char pointer in C

Unfortunately problem looks for me to be quite complex. I’m having set of structs and function. Pardon me for terrible naming. hashmap.h #ifndef HASHMAP_H #define HASHMAP_H typedef struct HashMapNode HashMapNode; struct HashMapNode { char *key; int value; HashMapNode *collision; }; typedef struct { int size; HashMapNode **map; } HashMap; HashMap *hashmap_new(size_t size); HashMapNode *hashmap_node_new(HashMapNode *node);

Read More
C#

I require help understanding how to test c code with provided test states and understanding a makefile

The unit I am doing required us to code an elevator system. I have the code for each file we have been asked for but do not understand how they have asked us to test it. We’ve been provided a zip file with tests and I am working in a virtual machine. I just feel

Read More
C#

Creating a struct referencing itself in C using custom type

I would like to create a struct with pointer to the property of the same type. Ideally I would like to go for something like this, but this causes compilation error: typedef struct { int data; Node *next; } Node; Solution I’m going for in this scenerio is: typedef struct Node_s { int data; struct

Read More
C#

Creating a type referencing itself in C

I would like to create a struct with pointer to the property of the same type. Ideally I would like to go for something like this, but this causes compilation error: typedef struct { int data; Node *next; } Node; Solution I’m going for in this scenerio is: typedef struct Node_s { int data; struct

Read More