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
4
votes
1answer
68 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 ...
4
votes
1answer
47 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 ...
3
votes
2answers
75 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. ...
5
votes
1answer
140 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-...
2
votes
2answers
94 views

Get the Nth Term in the Fibonacci Sequence

I'm trying out a new editor (CLion) and I decided to try an old well known programming problem. I also decided to try out C99 rather than C89. This program calculates the nth term of the Fibonacci ...
3
votes
0answers
39 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 ...
16
votes
6answers
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 ...
3
votes
1answer
88 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 ...
9
votes
1answer
81 views

ASCII Mandelbrot Set “image” producer

As an exercise, I decided to try implementing a Mandelbrot Set viewer that produces ASCII images. Small Example: ...
3
votes
1answer
53 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 ...
4
votes
2answers
57 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: ...
4
votes
1answer
256 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 ...
4
votes
3answers
116 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 ...
4
votes
2answers
113 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 ...
3
votes
1answer
117 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 ...
2
votes
3answers
41 views

Command line test runner

This is a simple program to run a command-line program with given parameters and verify that it writes the expected output to stdout or stderr. The specification file is passed as the first argument. ...
2
votes
2answers
60 views

Parse IP address from a GPRS module reply

I'm writing a parser to get the IP address from a string I get from a GPRS module. Examples of the string I get from the GPRS module: +QIACT: 1,1,1,\"10.162.143.228\"\r\n\r\nOK\r\n +QIACT: 1,1,...
7
votes
2answers
256 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 ...
3
votes
0answers
925 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 ...
4
votes
1answer
240 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 ...
1
vote
2answers
720 views

Function to scan input to string buffer in C

I have written a function that reads standard input, ignores initial whitespace and fills the buffer with that data. I think that it is a bit large and cumbersome, can you please tell me what can be ...
3
votes
3answers
87 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 ...
4
votes
1answer
1k 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 ...
4
votes
0answers
235 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 ...
7
votes
2answers
1k 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: ...
4
votes
2answers
131 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 ...
6
votes
1answer
208 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 ...
2
votes
2answers
207 views

IPC using pipes

I have simulated the conversation between a caller and receiver using fork and pipe. The parent process is the receiver and the child process is the caller. Each message is terminated by a newline. ...
4
votes
2answers
730 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 ...
0
votes
1answer
46 views

colorprint - part 2

This is a followup of the last review to comply with meta's rules. In the last, I posted a small library called colorprint and got some helpful pointers from chux ...
3
votes
1answer
54 views

colorprint - An ANSI Escape sequence console writer mini-library

I wrote this a long time ago. I came back to it and decided to clean it up a little. It uses the preprocessor and C99 anon structs to make a flexible python-like ...
3
votes
0answers
552 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 ...
11
votes
3answers
545 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 ...
4
votes
1answer
53 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 ...
6
votes
2answers
164 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 ...
11
votes
2answers
955 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) ...
18
votes
3answers
9k 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 (...
5
votes
1answer
133 views

Calculating diagonal difference

I was trying to solve a problem concerning the difference of the diagonal sums of a matrix (using C99): ...
2
votes
1answer
850 views

Postfix evaluation using a stack in c

I have written a program to evaluate a postfix expression using a stack. I had my stack implementation using a linked list reviewed here, so I am only including the header file here. I have taken ...
5
votes
2answers
316 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 ...
3
votes
4answers
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 ...
5
votes
1answer
78 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: ...
4
votes
2answers
206 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 ...
7
votes
2answers
172 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 ...
6
votes
1answer
150 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 ...
8
votes
4answers
2k 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 ...
4
votes
2answers
227 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: ...