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
8
votes
2answers
176 views

Hand Coded State Driven Lexical Analyzer in C With Unit Test Part A

This code review is presented in 3 questions due to the amount of code: Part A (this question) contains the Lexical Analyzer and the main portion of the unit test code. Part B contains the lower ...
32
votes
5answers
59k views

Brute Force Algorithm in C

This is a simple brute force algorithm that I have programmed in C. All the program does is print out every possible combination of the given alphabet for the ...
35
votes
9answers
70k views

Using a for-loop or sleeping to wait for short intervals of time

I need to wait for short intervals of time in my program, but I really don't want to include unistd.h just to use sleep, so I'm ...
11
votes
1answer
349 views

Function to print a double - exactly

Rarely is the exact value of a double needed to be printed and only its leading significant digits, after rounding, are needed. It is a curiosity to see the exact ...
20
votes
4answers
515 views

Detecting unicorn and dinosaur compilers

Rumor is that the next version of C will disallow sign magnitude and ones' complement signed integer encoding. True or not, it seems efficient to not have to code and test for those rare encodings. ...
8
votes
5answers
3k views

Macro for allocation in C

As we all know, the syntax of allocating memory is a bit clunky in C. The recommended way is: int *p; int n=10; p = malloc(n*sizeof *p); You can use ...
6
votes
1answer
664 views

UTF-8 encoding/decoding

I have two functions, a collection of possible error codes, and a unit-testing framework. The parsing of a character into its unary prefix and payload is handled by a few named functions and macros <...
5
votes
1answer
78 views

Hand Coded State Driven Lexical Analyzer in C With Unit Test Part C

This review is presented in 3 questions due to the amount of code: Part A contains the Lexical Analyzer and the main portion of the unit test code. Part B contains the lower level unit tests called ...
12
votes
4answers
4k views

Algorithm for Run Length Encoding - String Compression

I attempted a problem from the Cracking the Coding Interview book. The following input: aabcccaaa should give the following output: ...
11
votes
3answers
3k views

Coin Change: Minimum number of coins

Problem: You are given n types of coin denominations of values \$v(1) < v(2) < ... < v(n)\$ (all integers). Assume \$v(1) = 1\$, so you can always make change for any amount of money \$C\$....
10
votes
2answers
591 views

An attempt at a toy Vm

I usually use c++ so it may not be best practice for c. This is a stack based toy vm and as a result it is very primitive, and it has no bitwise instructions 64k might be a bit overkill for a toy vm. ...
7
votes
4answers
3k views

'do { statement; } while(0)' against 'statement' when writing C macro? [closed]

Which one of the following is preferrable and why when writing C macro? Type 1 #define I2C_START() I2C_WAIT_IDLE(); SSP1CON2bits.SEN = 1 Type 2 ...
5
votes
1answer
211 views

Termios/Xterm line editor for APL interpreter

As an interesting sub-part of an interpreter -- just the Read part of the REPL -- I present my raw-mode line-oriented editor that I intend to use for my APL interpreter. (The Eval part has been posted ...
12
votes
1answer
2k views

fgets() Alternative

size_t readline_tostring(char * restrict dest, size_t size, FILE * restrict stream) fgets() is OK yet it has some short-...
10
votes
4answers
640 views

Writing computer generated music to a .wav file in C - follow-up

See the previous and initial iteration. See the next iteration. Now I have refactored the code according to many suggestions made in the first iteration. What's new: I attempted to deal with ...
2
votes
1answer
84 views

A trivial command line utility for trimming whitespace from lines in C - follow-up 2

The previous iteration at A trivial command line utility for trimming whitespace from lines in C - follow-up Note: the next iteration at A trivial command line utility for trimming whitespace from ...
4
votes
2answers
95 views

Two dimensional gaussian image generator in C

This is a follow-up question for Image Processing Median Filter in C. I am attempting to create a two dimensional gaussian image like below in C. The formula is as follows. The experimental ...
4
votes
1answer
47 views

Hand Coded State Driven Lexical Analyzer in C With Unit Test Part B

This review is presented in 3 questions due to the amount of code: Part A contains the Lexical Analyzer and the main portion of the unit test code. Part B (this question) contains the lower level ...
2
votes
2answers
81 views

Common Unit Testing Code – Follow Up

This question is a follow up question to the Common Unit Testing Code portion of my lexical analyzer questions. My primary concern is the code in the header file and the C source file that implements ...
143
votes
17answers
18k views

Disproving Euler proposition by brute force in C

I wrote a little bit of code to brute force disprove the Euler proposition that states: $$a^4 + b^4 + c^4 = d^4$$ has no solution when \$a\$, \$b\$, \$c\$, \$d\$ are positive integers. I'm no ...
23
votes
2answers
1k views

parcel: a JSON parsing library in C

I've created a JSON parsing library in C, and would like some feedback on it (feel free to submit a pull request on GitHub). Any and all suggestions are acceptable, but I would prefer if reviews were ...
33
votes
4answers
18k views

Recording audio in C

Please note there are newer revisions of this code, one here, and one here for continuous audio recording. This is a program I wrote as a .wav audio recording library for Linux. It was developed on ...
11
votes
1answer
3k views

ToyVM - a small and simple virtual machine in C - follow-up

(See the previous and initial iteration) Now I have refactored the code in order to conform to the suggestions made in the answers to the first iteration. I have this: toyvm.h: ...
8
votes
5answers
5k views

Euler #3 largest prime factor

Problem Statement This problem is a programming version of Problem 3 from projecteuler.net The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of a given number N?...
11
votes
1answer
1k views

FIFO for embedded systems

I wrote a simple FIFO based on pieces of code I found online. It's intended for embedded systems with very restricted RAM. It's supposed to be very simple and efficient. The size is always power of 2 (...
9
votes
2answers
349 views

ToyVM - a small and simple virtual machine in C + FizzBuzz demonstration

(See also the next iteration.) I have this small virtual machine. What is there: Stack and, thus, recursion. Conditional and unconditional jumps and, thus, choice and iteration. What is not there:...
12
votes
2answers
4k views

More efficient way to retrieve data from JSON

I am using the jsmn JSON parser (source code) to get extract data from a JSON string. jsmn stores the data in tokens that just point to the token boundaries in the JSON string instead of copying the ...
12
votes
1answer
5k views

Decompression implementation

Here is a simple decompression implementation. I'd very much appreciate any advice or comments about the structure/logic of the program, style of the code, or reusability of the features. I'm a real ...
10
votes
1answer
1k views

Recording audio in C 2.0

I posted my audio recording program to Code Review before, and received a stern review along with the other reviews that caused me to rewrite the entire code base. Here is what I would like reviewed: ...
5
votes
2answers
85 views

A trivial command line utility for trimming whitespace from lines in C - follow-up

See the previous iteration: A trivial command line utility for trimming whitespace from lines in C Note: see the next iteration at A trivial command line utility for trimming whitespace from lines in ...
5
votes
1answer
273 views

Simple spinlock for C using ASM

This is my second attempt to make simple lock using extended assembly. See https://stackoverflow.com/questions/37241553/locks-around-memory-manipulation-via-inline-assembly/37246263 The code: ...
5
votes
4answers
289 views

Product of all but one number in a sequence - Follow Up

This question is a follow up question to the Product of all but one number in a sequence. I am posting a new code here with taking into consideration the suggestions of [Edward], [CiaPan], [chux], [...
3
votes
1answer
342 views

Computational verification of Collatz conjecture

Prerequisites The typedef name uint128_t designates an unsigned integer type with width exactly 128 bits. The ...
9
votes
3answers
6k views

StringBuilder in C

Lots of languages have something that lets you build up a dynamically-sized string with minimal overhead. C doesn't, and I found myself using code that did that manually in a couple of places, so I ...
8
votes
2answers
130 views

Game of Runes: revised version

I have created a game called Runes in C. It is similar to Chess, but has a bigger board and different pieces. I would like to know how I can improve the code, for example, with user interface ...
8
votes
2answers
261 views

Simple compression reloaded++

As a follow up to my previous question I've improved the code + algorithm. The compression now works the following way: Each character is followed by a length byte. The top 3 bits of that byte denote ...
6
votes
2answers
159 views

Unicode-capable symbol table (N-way search tree with hash buckets)

As in my previous question, this module is coupled with its own testing framework. As a symbol-table for a Unicode-capable programming language interpreter, I decided to combine the 3 types of ...
6
votes
2answers
509 views

Embedded IoT: local data storage when no network coverage

I am working on a part of an IoT project where I have been given a task to develop a mechanism to store data locally when there is no network coverage or if the network is down for some reason. Our ...
6
votes
1answer
200 views

Encoding data into integer handles for language interpreter

As an integral part (pun intended) of my APL interpreter (previous questions: 1 2 3 4), this suite of functions converts any data into integer handles. APL operates on arrays of data cells, so with ...
5
votes
3answers
602 views

Please review my solution to Project Euler program 1

Can someone give me suggestions on how to improve this program? The objective is to find the sum of all the multiples of 3 or 5 below 1000. ...
5
votes
3answers
2k views

Implement strtod parsing

In this comment the OP wrote, I am a newbie so i would like to know how would i parse the negetive numbers/arguments ? In this answer @200_success showed an implementation using the strtod ...
5
votes
4answers
4k views

`atof` implementation

I have implemented the atof function. Here is my implementation ...
5
votes
1answer
381 views

Modular exponentiation without range restriction

A typical modular exponentiation may be coded using the following algorithm. ...
4
votes
3answers
58 views

Embedded IoT: local data storage (Updated)

I have made most of the review changes based on feedback I have got from here. Now I am back here for a second review to further better my code. Before posting the changes, somethings I haven't ...
4
votes
2answers
253 views

Two dimensional bicubic interpolation implementation in C

This is a follow-up question for Two dimensional bicubic interpolation implementation in Matlab and Two dimensional gaussian image generator in C. Besides the Matlab version code, I am attempting to ...
4
votes
3answers
423 views

Parse 2D matrix, 2 versions

I'm writing a little C program that computes matrices (for learning purpose). The matrix is fed through arguments in the following form : "{{43,543.324,34},{43,432,87}}" The user doesn't give the ...
4
votes
4answers
138 views

Image Processing Median Filter in C

I am attempting to perform Median Filter with size 3 x 3 in C language. The function MedianFilter33 has been implemented as follows. The experimental implementation ...
3
votes
1answer
79 views

Testing for divisibility of numbers - follow-up

(Here is the follow up question) I had another go at trying to speed up my program described in my previous question. JS1's answer was particulary helpful and now my code is only about 20% slower ...
3
votes
1answer
97 views

Data Structures in C (Single Linked List) - Follow-up

This is a follow-up from my previous question! I cleaned up the code and added all the notes from the answers. I have also updated the code on github LinkedList.h ...
3
votes
4answers
493 views

Simple calculator in C V2

My last question had a lot of views (over a 1000) so I decided to apply what I learned from the previous question and revamp the program. I learnt a lot from posting that question (functions, how to ...

1
2 3 4 5
8