Questions tagged [c]

C is a general-purpose computer programming language used for operating systems, games, and other high performance work and is clearly distinct from C++. It was developed in 1972 by Dennis Ritchie for use with the Unix operating system.

Filter by
Sorted by
Tagged with
-3 votes
0 answers
30 views

Dice Rolling Game in C language how to get three different functions one for the dice, one for the game , and the main to call the game? [closed]

it deals with as many players as u want with 6 dice, and wants to find the sum for each player and then find the player that has the biggest sum but the sum is the same for every player and I don't ...
  • 1
-2 votes
1 answer
50 views

Moving increments into condition checks? [closed]

I am reading the second edition of the C Programming Language by Kernighan and Ritchie. In it, the authors introduce things like: ...
  • 135
2 votes
1 answer
99 views

Multithreaded Conway's Game of Life implementation written in C and Java using JNI

I had some multithreading C programming experience from school last year but I wanted a bit more so I tried to program a Conway's Game of Life implementation from scratch. Code is mainly written in C ...
7 votes
2 answers
1k views

Proper implementation of signal handler and multithreading (pthread)

I am trying to implement a "proper" signal handler that works correctly for multiple threads, and to be as C-standard-conforming and POSIX-conforming as possible. The below is my ...
4 votes
1 answer
86 views

Instance specific code generation

Disclaimer: I've asked this question before on Stack overflow and got a response that this place would be a better fit so I am copy pasting the question here. I've come up with two different ...
8 votes
2 answers
188 views

Tar implementation

I am writing a tar implementation for education purposes and I started with reading from a tar file and printing the file content. I use recursion for getting the next tar header and googled "...
6 votes
2 answers
214 views

Bellman-Ford optimisation in C with Shortest Path Algorithm (SPFA) and Small Label first (SLF)

I am trying to code an optimized version of Bellman-Ford algorithm. This post is a continuation of the following post Bellman-Ford optimisation in C in which I posted a first version of the classic ...
  • 111
5 votes
2 answers
2k views

Bellman-Ford optimisation in C

Here is my current code: ...
  • 111
3 votes
3 answers
690 views

Compute the sum of even numbers between two values

Recently I was watching two YouTube videos criticizing a function which sums the even elements in an inclusive range, the original function looks like this: ...
  • 133
3 votes
1 answer
114 views

Damerau-Levenshtein distance performance improvements

I am working on a Python C-extension to calculate Damerau-Levenshtein distance. I am not really familiar with C at all--I just know that it generally has better performance. However, I am not sure how ...
3 votes
3 answers
124 views

In-place recursive quick sort in C

Here's my second program in C, and my time/space analysis of this code. I have been reading Modern C and I attempted this challenge on page 26. The prior pages are pretty much the only exposure I have ...
8 votes
4 answers
654 views

Run command in a child process

Inspired by this answer from SO, I try to find a version of fork()/exec()/wait() which: starts a child process; catches stdout, stderr and return code separately; properly handles all possible errors ...
3 votes
3 answers
96 views

Solution to Codejam 2021 1C (Closest Pick) in C

The following code is my solution to the Closest Pick problem from Codejam 2021. You are entering a raffle for a lifetime supply of pancakes. N tickets have already been sold. Each ticket contains a ...
  • 287
4 votes
3 answers
116 views

quadratic probing hashmap and its time efficiency

I am writing small a hashmap library (not full featured yet) but I have some questions about the algorithm I wrote, the formula I hope I got right from wikipedia and general things. Measured ~14.3 ...
14 votes
4 answers
3k views

Max-heap implementation in C

I have tried to implement my Heap in C. The following are the 13 operations defined: build_maxheap insert exctract_max (delete heap max root) max_delete (delete an element or key) max_heapify clear ...
  • 423
3 votes
4 answers
273 views

Create a structure to store student data and display all the records in the array

I'm still a beginner and I wanted to ask if I'm doing my code right? The comments are the tasks that I need to do for each function. ...
  • 31
10 votes
5 answers
727 views

Follow Up: struct sockaddr storage initialization by network format-string

This is a follow up to: struct sockaddr_storage initialization by network format string First of all thanks to @Haris, @Toby Speight, @G. Sliepen and @chux - Reinstate for their help. I learned a lot ...
3 votes
1 answer
94 views

Binary Search Tree implementation in C [1]

I have tried to implement my Binary Search Tree in C. The following are the 18 operations defined: create a bst is_empty insert delete clear find find_min find_max height size depth level order ...
  • 423
4 votes
3 answers
527 views

Command line calculator in C

This code is an arithmetic parser as is the code in a previous question of mine. However this parser handles floating point arguments and mathematical functions, and handles them without needing to ...
5 votes
1 answer
191 views

Basic recursive descent parser in C

The purpose of this code is to evaluate simple integer expressions that make use of the C arithmetic and bitwise operators while respecting C operator precedence and parenthesis. I wrote this code ...
8 votes
3 answers
495 views

struct sockaddr_storage initialization by network format string

I am writing a wrapper library for network functionality in C and wanted to let the user let the user initialize a struct sockaddr_storage with a format string. Format ist like: "proto:host:port/...
4 votes
1 answer
129 views

Vectorized 16-bit addition in Standard C

The idea is to add a given 16-bit number N to each element of an array of 16-bit integers of arbitrary length, taking advantage of 64-bit integer types and instructions to perform the additions 4 at a ...
4 votes
1 answer
78 views

Minimalist Recursive File Watcher (MacOS & Linux)

Looking for feedback, bugs, performance reports, and general code review of this simple file-watcher. Basic algorithm: The MacOS version just sets the relevant paths to be watched from the CLI ...
  • 141
12 votes
4 answers
1k views

Recursive merge sort in C

Here's my first program in C, which is not my first language. I have been reading Modern C and I attempted this challenge on page 26. The prior pages are pretty much the only exposure I have had to C, ...
5 votes
1 answer
130 views

Dynamic array type using void pointers C

I made my own dynamic array type using void pointers. I'd like to know what you think of my implementation. void pointers are nice but I fear they may be inefficient. The compiler cannot tell what ...
8 votes
4 answers
167 views

Array List C implementation

I want to show you my implementation of the array list in C. Is there something I can improve or fix? Header ...
  • 161
2 votes
0 answers
48 views

a C/Python X server interface extension package

The project is named winlin; it's a portmanteau of the words window and Linux. I'm working on a CPython extension to interact with the X server and manipulate windows. I don't have a ton of ...
0 votes
1 answer
57 views

Doubly Linked List of integers

I wrote a working linked list program in C. What can I improve in my code in your opinion? The first thing I think about is doing unit tests. I want to learn TDD. I'm not sure if it is a good idea to ...
  • 161
2 votes
1 answer
81 views

A singly linked list implementation

Here's yet another implementation of a singly linked list. You may base your review on the following questions: Review goals: Is the API well thought of? Does this design include undefined behavior, ...
  • 929
1 vote
4 answers
120 views

Queue using doubly linked list

I have implemented my queue based on doubly linked list. The codes is tested and works, however, I am interested in some improvement ideas, thanks Based on some review remarks on my previous ...
  • 423
0 votes
4 answers
108 views

Stack using doubly linked list

I have implemented my stack based on a doubly linked list. The code is tested and works; however, I am interested in any improvement ideas. ...
  • 423
6 votes
2 answers
87 views

First attempt at making a sobel edge detection filter in c

I made a borders filter in C. It works properly, but I think it could be optimized and better designed; the formatting is abysmal. It uses too many lines for the border cases and has too many ...
  • 63
11 votes
10 answers
2k views

Trim leading/trailing space in a string

I'm practicing C and wrote a function to trim leading/trailing spaces in a string: ...
4 votes
4 answers
1k views

Doubly linked list optimally defined over 17 operations in C [4]?

Previous versions of this question First Version Second Version Third Version Fourth Version Changes I built upon the previous singly linked list and implemented a doubly linked one. You are not ...
  • 423
0 votes
0 answers
45 views

singly linked list optimally defined over 17 operations in C [3]?

Previous versions of this question First Version Second Version Third Version Changes I took into consideration previous remarks, I will leave the design remarks for later. You are not allowed to <...
  • 423
2 votes
2 answers
223 views

singly linked list optimally defined over 17 operations in C [2]?

Previous versions of this question First Version Second Version Changes I added these operations: Pop_back Pop_front You are not allowed to insert_sll at the ...
  • 423
3 votes
2 answers
358 views

singly linked list optimally defined over operations in C?

I have implemented my singly linked list in C and I tried to do it with the most efficient code as possible. Is there any place for improvement? This post is the second version. First version of this ...
  • 423
3 votes
1 answer
139 views

Singly linked list optimized for search & insert in O(1)

I have tried to implement my singly linked list to be optimal in the sense that when inserting I don't have to search for the tail and then chain the new node to it, I just keep track of the tail and ...
  • 423
4 votes
1 answer
83 views

Perform a permutation on an array in MIPS assembly

I’m currently studying computer science at university and I’d been tasked with writing a MIPS assembly program that performs a permutation on an array. I’m asking here because my code actually worked ...
3 votes
2 answers
65 views

Extensible typing system for a strongly-typed DSL

I recently finished cleaning up my code in a compiler/interpreter for a strongly-typed domain-specific language, which makes use of three sorts of types: Compile-time enumerated types: Have one of a ...
  • 131
3 votes
2 answers
140 views

Print decimal integer

This is an x86-64 Linux program to print a non-negative decimal integer. I would appreciate any simple optimizations for size and readability. I am aware that division by a constant is usually done by ...
  • 1,016
3 votes
2 answers
95 views

C macro based dynamic array library

This library is a fork of eteran/c-vector. It is macro based, so that it is generic, without void pointers and additional functions. This of course means that it has the downsides of macros in C. The ...
1 vote
2 answers
102 views

Logistic regression using gradient descent

My code seems to work fine, but I'm interested in how I can make it faster. I really just want to reduce any wasteful computation (for instance ...
1 vote
2 answers
87 views

(Dog) Agility - Penalties Calculator

I have written the following code. I hope to improve how it completes the given task, since I think that my code - even if "properly working" - is quite "brute" and it could ...
3 votes
3 answers
126 views

Follow up: A chat server using the select() API

This is a follow up to my last question: Multiperson chat server using the select() API Changes: After much fine critique, I made the following changes to the code: Removed redundant casts and ...
  • 929
8 votes
1 answer
305 views

Solution to Codejam 2019 1A (Pylons) in C

The following is my solution to the Pylons problem from Codejam 2019: https://codingcompetitions.withgoogle.com/codejam/round/0000000000051635/0000000000104e03. Our Battlestarcraft Algorithmica ship ...
  • 287
7 votes
2 answers
733 views

Event functionality in C

I am beginner to intermediate and wanted to write a little event code in c. It's one header file with 108 line pure code and it does what I was thinking it should be like for me. EventListener.h ...
11 votes
2 answers
1k views

Multiperson chat server using the select() API

I followed the Beej's Guide to Network Programming. The program acts like a multi-user chat server. One connects and sends a message to the server, which is forwarded to all that are connected. There'...
  • 929
3 votes
1 answer
49 views

Wipe a directory tree

The idea here is to destroy the data in a directory tree by finding any files in it and overwriting their data with garbage before deleting them. The function returns minus the number of errors ...
0 votes
3 answers
131 views

Simple stack of integers

I've a simple push/pop implementation in my program: ...

1
2 3 4 5
77