New answers tagged c
2
votes
K&R excercise 1-21 Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing
The "ternary expression"
You've used the ternary expression as a replacement for a conditional statement in the following.
...
2
votes
Inserting into a linked list
If we're assuming that head is not NULL, so let's split up the responsibilities: writing a separate function that finds the tail ...
2
votes
Binary Search Tree implementation in C [1]
Style
You mix braces and not using braces freely throughout your code. While this works, it leaves open the possibility of adding to branches of conditionals or to loops and forgetting to add braces, ...
3
votes
Max-heap implementation in C
It strikes me that there is an opportunity for some of your functions to be very straightforward preprocessor macros.
...
8
votes
Accepted
Term only, arrow-only category foundations in C
General Observations
Possible bug, in the current implementation the dom and cod Term pointers are being assigned the value of ...
2
votes
Schedule using binary tree in C
Indentation
More than a single space for indentation makes code much easier to read. Four spaces is a very common convention for C.
Nested conditionals
Let's consider one function, with improved ...
6
votes
Arena Allocator in C
Poor naming
Based on its name and type and type alias, I expect Arena.buffer to be a pointer to the starting address of the arena from which memory is being ...
1
vote
Computing the smallest number of the form floor(8^N / 7) that is greater or equal to a number
Firstly, there's absolutely no comments for the reader to understand the purpose of this calculation, i.e. what it might be used for. The name getsize() isn't much ...
8
votes
Accepted
"Frankenmallow" C code uses arc4 to choose flavors and coatings in arrays for mallow ideas, w/ switch cases, and countdown, functions: rngch ctdn
The formatting is really really odd. I see a lot of extraneous newlines, weird indentation, and brace style.
Further, having holdreturn declared before it's ...
7
votes
Accepted
Arena Allocator in C
char pointer
typedef char* Arena_ptr;
That seems weird.
I mean, it's your Public API, you get to define it however you want,
signed char or unsigned or whatever.
...
-2
votes
4
votes
Computing the smallest number of the form floor(8^N / 7) that is greater or equal to a number
As chux said:
Perhaps more research will lead to a no test approach.
I've found this solution, which is indeed C++ instead of C but let's look past that for now:
...
2
votes
Computing the smallest number of the form floor(8^N / 7) that is greater or equal to a number
For fun, consider a tree of depth log2(X_MAX).
Is there a more direct way (loop-free) to compute this number than computing a level and then going back?
A simple binary decision tree with 4 compares....
9
votes
Accepted
Computing the smallest number of the form floor(8^N / 7) that is greater or equal to a number
is there a more direct way?
Look up table
With 32-bit int, level is so limited in range as ...
2
votes
Computing the smallest number of the form floor(8^N / 7) that is greater or equal to a number
0x49249249
consider giving it a name - approximation of the multiplicative inverse of 7 mod the power of 2 that is the least multiple of 3 no less than the number ...
4
votes
K&R Exercise 5-10. reverse Polish calculator
Return values
Several of your functions print error messages. While it's fantastic that you correctly print these messages to stderr instead of ...
Top 50 recent answers are included
Related Tags
c × 4102beginner × 567
performance × 555
strings × 415
algorithm × 336
linked-list × 261
memory-management × 193
array × 184
programming-challenge × 161
linux × 142
parsing × 134
io × 133
reinventing-the-wheel × 130
file × 125
pointers × 115
sorting × 103
homework × 94
multithreading × 87
integer × 83
c++ × 81
console × 79
formatting × 79
game × 78
hash-map × 74
bitwise × 74