Questions tagged [c99]

C99 is a standard for the C programming language. It replaces the previous C89 standard, and is succeeded by the C11 standard. C99 added inline functions, C++-style comments, allows intermingled declarations and code, as well as multiple other language and library fixes and additions.

Filter by
Sorted by
Tagged with
18 votes
3 answers
12k views

Implementation of the ls command with several options

As part of a past assignment, I've expanded on this implementation of ls to have more options available, including non-standard ones. It currently supports these (...
Jamal's user avatar
  • 34.8k
16 votes
6 answers
2k views

Avoiding repetition when using the "snprintf idiom" to write text

I'm writing a function to stringify a nested struct. I'm using snprintf to pre-calculate how much space I'll need to allocate. The problem is, it's extremely ...
Carcigenicate's user avatar
11 votes
3 answers
622 views

Dijkstra's algorithm in C99

I just implement Dijkstra's algorithm in C99. Can you review my code please? I'm looking for any mistake, performance improvement or coding style errors. main.c ...
Colt's user avatar
  • 213
11 votes
2 answers
1k views

Implementation of the ls command with several options - follow-up

I've made vast improvements to my previous ls implementation, including: Added new flags: -g (omit owner listing) ...
Jamal's user avatar
  • 34.8k
9 votes
1 answer
180 views

ASCII Mandelbrot Set "image" producer

As an exercise, I decided to try implementing a Mandelbrot Set viewer that produces ASCII images. Small Example: ...
Carcigenicate's user avatar
9 votes
1 answer
2k views

Rust-like "Result" in C - nicer error handling

There are frequently things I miss when using C; one of them is a nice error-handling (exception-like) system. After trying Rust, I realized I could implement something similar in C itself. So here's ...
Justin's user avatar
  • 3,295
8 votes
4 answers
5k views

Simple compression algorithm

An implementation of a simple compression algorithm that's featured in a programming practice book. My goals: Robust: All error conditions must be handled properly. The specification indicated in ...
OregonTrail's user avatar
8 votes
1 answer
312 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 ...
Panic's user avatar
  • 287
8 votes
4 answers
1k views

Checksum a Game Boy cartridge

I wrote a program to insert a checksum into a Game Boy cartridge. Here is a spec of the cartridge header, but I'll include the relevant information here, as well. The header checksum is defined as ...
S.S. Anne's user avatar
  • 1,715
8 votes
1 answer
169 views

Random walk on a grid

...
JCC's user avatar
  • 83
8 votes
1 answer
135 views

Simple reminders timer in C99 for POSIX

This is my first time trying out C. Simplicity was the main objective. Signals are not handled and memory is not freed (program is very small, and the OS should take care of that when program exits). ...
basedN1F48A's user avatar
7 votes
2 answers
3k views

C code to convert hexadecimal string to base64

I've written a program to convert a hex-encoded string to base64, and here is my code. My main concerns are: Optimizations - Is my code sufficiently optimized and if any more optimization is possible....
Vedant Jadhav's user avatar
7 votes
2 answers
3k views

C - Generic ArrayList / Dynamic Array Implementations

As a small project to refresh my C and data-structure knowledge, I decided to write a generic ArrayList (as in Java). This is my most current version: ArrayList.h: ...
Hericks's user avatar
  • 351
7 votes
2 answers
263 views

Reverse engineering Darkstone game archives

Reverse engineering old games is something I do every now and then. This time, I took a shot at this old RPG called Darkstone. The bulk of the game's data is stored in archive files with the ...
glampert's user avatar
  • 17.1k
7 votes
2 answers
462 views

Simple console JSON formatter

I am writing simple formatter for valid JSON. Is reads JSON data from stdin and writes formatted output to stdout. Goals: given valid input produce valid formatted JSON output constant memory usage ...
sineemore's user avatar
  • 1,785
6 votes
1 answer
170 views

Simple procedural image patterns

I have these functions for generating procedural debug data for another piece of code related to image processing. The three following functions generate these simple mechanical patterns, which are ...
glampert's user avatar
  • 17.1k
6 votes
2 answers
236 views

Implementation of the ls command with several options - follow-up 2

I've made more improvements from previous iterations and my own, including: Added the -n flag (print owner and group IDs instead of names) Eliminated some ...
Jamal's user avatar
  • 34.8k
6 votes
1 answer
3k views

A Thread-Safe FIFO in C99

I started a little weekend project to try and learn how to multithread with pure C99 and POSIX threads. The project is composed of three threads, input, processing, and output, which communicate with ...
Bernardo Meurer's user avatar
6 votes
1 answer
314 views

Counting sort implementation in C

I've just implemented counting sort in C and would like to hear your opinions on it. As I'm usually being rather picky when rating other people's code, please go ahead and be picky, too -- I will try ...
ljrk's user avatar
  • 879
5 votes
2 answers
141 views

Generating Pascal's Triangle in C99

I recently completed the Pascal's Triangle challenge on leetcode. I would like to have my code reviewed. You don't need a leetcode account to see the description of the challenge linked above, but for ...
Gabriel's user avatar
  • 1,053
5 votes
2 answers
342 views

Stack implemented using a single linked list

I am studying data structures and I have implemented a stack using a linked list. stack.h ...
In78's user avatar
  • 643
5 votes
1 answer
83 views

Program to tell which if any of three numbers is in the middle

I wrote this program, and it does what it asks, but it's so big and ugly. What can I change? Some examples: ...
EnderEgg's user avatar
5 votes
1 answer
165 views

Calculating diagonal difference

I was trying to solve a problem concerning the difference of the diagonal sums of a matrix (using C99): ...
Knox Root's user avatar
5 votes
1 answer
3k views

Convert a hex string to base64

I wrote a program that converts a hex-encoded string to base64. It's my solution to the first of the Cryptopals challenges. My main concerns are: Portability. I don't want to rely on implementation-...
flornquake's user avatar
4 votes
3 answers
332 views

Linked List written in C

I have been learning data structures and dynamic memory allocation in C. As a learning experience, I have written this linked list implementation. I really appreciate the feedback I've received on the ...
Faraz's user avatar
  • 513
4 votes
2 answers
245 views

Algorithm (and tests) to parse lists of unsigned 32-bit ints from strings in C

What? I have an algorithm that parses comma separated lists of unsigned 32-bit ints from strings. Here is an example of what a list could look like: ...
rzetterberg's user avatar
4 votes
1 answer
246 views

200 line Brainfuck Interpreter

I wrote a simple brainfuck interpreter in C99. Coming from a background of C++ made the task easier, but still there is some stuff I had to get used too. The program accepts a path to a brainfuck file ...
William Redding's user avatar
4 votes
3 answers
139 views

Simple photomosaic generator

I wrote an implementation of Robert Heaton's Programming Exercise for Advanced Beginners #4 (photomosaics) in C99 using the MagickCore library. The full code is as follows: ...
Wilson's user avatar
  • 43
4 votes
2 answers
91 views

Link list working

I wrote this singly linked list and it worked fine,Now can anyone review my code. I want to do some more clean my delete and add function. And some abstraction. ...
Dark debo's user avatar
4 votes
2 answers
165 views

File chunk buffer for Windows programs

The purpose of the ChunkBuffer code below is to designate a "chunk" from a given input file and to loop that chunk (if needed). Its operation is similar to the ...
user7023624's user avatar
4 votes
2 answers
93 views

String joining function in C

I wrote a function that joins a collection of Strings with a delimiter. It's based on Java's version of the function. I'm assuming C has some similar built-in. Example: ...
Carcigenicate's user avatar
4 votes
2 answers
1k views

Dynamic Array container in macros

The code below is an attempt to mimic std::vector from the C++ standard library in the C language. The implementation is purely macros, in the C99 dialect, and ...
user7023624's user avatar
4 votes
3 answers
165 views

Dynamic list in C99

I'm experimenting with C after working in high level languages for the last 15+ years, and trying to feel comfortable with C code bases again. One thing I needed for the code I'm writing was a ...
KallDrexx's user avatar
  • 221
4 votes
2 answers
434 views

Hangman v2 written in C

This is a follow up to my previous Code Review, and I have incorporated feedback I received in this revision of the code, along with some other improvements. I would appreciate your feedback on this ...
Faraz's user avatar
  • 513
4 votes
1 answer
239 views

C functions for fast IO for competitive programming

In some (perhaps not well-designed) competitive programming problems, the runtime and score is dependent on how fast your program can process input. Therefore I've written a small C99 library with ...
Stand with Gaza's user avatar
4 votes
1 answer
2k views

Beginner Console Conway's Game of Life in C

For an Information System Security course I've applied to, I need to learn C and decided to start learning it yesterday. Conway's Game of Life has historically been a good project to start with, so I ...
Carcigenicate's user avatar
4 votes
1 answer
1k views

Generic fixed-size Stack implementation in C

Coming mostly from C#/Java background, I'm trying to implement a simple fixed-size stack data structure in C. The main concern about the "fixed-size" part is that pushing new elements to a full stack ...
galah92's user avatar
  • 223
4 votes
2 answers
336 views

Low level string manipulation functions in C

I'm working with a legacy program that does a bunch of markup manipulation, some of it higher-level and specific to the proprietary markup, some of it lower level string stuff. I rewrote and ...
brian_o's user avatar
  • 839
4 votes
1 answer
257 views

static memory block allocator in c99

I wrote this snippet to allocate blocks of memory, whose sizes and number are available during initialisation. I choose to equally divide the statically allocated memory. There are some error checks ...
rookie's user avatar
  • 143
4 votes
1 answer
3k views

Sprite animation with SDL2

For the past few days I've been trying to learn how to animate 2D sprites using SDL2. For that purpose, I've taken a 6 frames animation from a Pokémon game and made a PNG image out of it : The way I ...
frostblue's user avatar
  • 137
4 votes
1 answer
86 views

YAGOP - Yet Another Generic Object Pool

While thinking about this question it struck me that one problem of linked data structures always seems to be loss of memory locality and performance could possibly be improved if all allocated nodes ...
ChrisWue's user avatar
  • 20.3k
4 votes
0 answers
289 views

Fast ray/triangle intersection code in C

I wonder if someone is familiar with ray/triangle intersection algorithms and can help me optimize them? Here are my implementations of two ray/triangle intersection algorithms in C. The first is the ...
Stand with Gaza's user avatar
3 votes
4 answers
2k views

Simple singly linked list implementation in C

I have implemented a LinkedList with the ability to add, get elements from a particular position and ability to show all the elements in the array in to the console ...
codez's user avatar
  • 969
3 votes
3 answers
124 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 ...
Panic's user avatar
  • 287
3 votes
3 answers
99 views

Reading and classifying lines from a file

I'm new to C which I'm learning in university now, and I'm not sure if the following is considered in C good practices or not. For an assignment in a simple Classification problem I wrote the ...
Gilad Green's user avatar
3 votes
1 answer
137 views

Clang preprocessor concatenates an extra space vs. gcc - standard C99

I maintain a C library project both on gcc and clang. I am looking for advice on how to make the following macros more portable, terse, readable or standard abiding. When I compile ...
OneArb's user avatar
  • 211
3 votes
1 answer
178 views

C99 JSON parser/writer

About I've decided to challenge myself and write a JSON parser in C99 (i've written them in C++ before, but never in plain old C), and here's what I ended up with, it works well from what I've tried. ...
Ricardo Silva's user avatar
3 votes
1 answer
119 views

Verbose Brainfuck Interpreter in C

I decided to try and write a Brainfuck interpreter in C as an exercise. This could have been written in one file, but I decided to split it up into a State "class" and an some interpreter methods. An ...
Carcigenicate's user avatar
3 votes
1 answer
1k views

Hangman written in C

I would like your feedback on any improvements that can be made to this Hangman game I have written in C. Specifically, improvements in terms of runtime and code organization. This game was a nice way ...
Faraz's user avatar
  • 513
3 votes
1 answer
81 views

Bar graph of Easter date distribution

Computing Easter for a given year is a classic computational problem. It is also one of the few cases when code seems to just have to live with magic numbers. Alternative to magic numbers: Decoding ...
chux - Reinstate Monica's user avatar