New answers tagged

2 votes

C safe getline()

let me know what I can do to improve it. Design flaw Somehow, the caller needs to distinguish between a call that immediately ended due to '\n' vs. ...
2 votes

C Macro Generic Linked List

General Observations Very interesting code and question. This looks like an attempt to write object oriented code in C. I've tried to do this myself, it has inherent problems. The use of ...
  • 19.9k
3 votes

C safe getline()

About the overall design: bool getLine(FILE *src, char **dest, size_t *size); This function is intended to be called like this: ...
  • 206
4 votes

Finding a function from a name within a string

A novel and interesting piece of code. A refreshing application. Why static? ...
3 votes

C Macro Generic Linked List

[Just a short review, more later] Not a 3-way compare data->size - *key is never negative as it is a wide unsigned subtraction and so does not meet "...
2 votes
Accepted

Return a random integer with a probability progression

Code doesn't match description The explanation corresponds to a uniform distribution (except that the last value may have lower likelihood (if pi reaches or crosses ...
  • 63.2k
3 votes

Return a random integer with a probability progression

OP has not posted a review goal. Perhaps add a clear goal. Below are some observations. Off by 1 random_int(1, 10) generates one of 9 values. Given ...
0 votes

Möbius function using iterators for prime factors

more later Is this solution common practice? Scant Comments As code lack code comments, what is truly happening is harder to discern than needed. Hard to tell what is really happing let alone ...
7 votes

Number System Conversions with strtol

chux and Toby already made many excellent points. I want to add one: Make the output useful by being less verbose Being verbose when printing an error message is helpful, but don't be verbose when ...
  • 38.3k
6 votes

Number System Conversions with strtol

Everything that chux said, and: The memory allocation is unused and leaked. Look at this: ...
  • 63.2k
7 votes
Accepted

Number System Conversions with strtol

Style review(indentation, comments, readability, etc.) Noise const serves no purpose with const int base in the ...
1 vote

Simple Memory Arena

Avoid macros Your code relies way too much on macros, to the point it doesn't even look like C anymore and is becoming unreadable. Take for example the first one: ...
  • 38.3k
3 votes

C/C++ hash looking in flat database compared to PHP

Overview and General Observations For a hobby programmer this is pretty good! Some of the common mistakes made are not in this code. Unfortunately I don't know the latest versions of PHP and really ...
  • 19.9k
1 vote

Non recursive binary search in C

The function signature doesn't make sense to me: size_t search_no_recursion(int *arr, int target, int start, int end) If we return the position as a ...
  • 63.2k
1 vote

Multi-threaded web server serving HTML, images, etc

Never do this: node_t *newnode = malloc(sizeof(node_t)); //create node newnode->client_socket = client_socket; //assign client socket If ...
  • 63.2k
1 vote

Standard C overflow-safe arithmetic functions

This is a good and interesting idea, and the actual integer math part of the implementation looks good. (And use of GNU C builtins should help efficiency.) But the type name ...
  • 2,787
2 votes
Accepted

Simulate 2-bit half adder with 2-bit inputs on Arduino without using logic gates

Avoid code duplication Your implementation is like that of a truth table: for all possible inputs, you have pre-calculated the output. That is one way of doing it. But instead of having lots of ...
  • 38.3k
5 votes
Accepted

LeetCode Daily Problem: Remove adjacent duplicated elements

Use proper formatting. This may be very basic, but the impact on readability is hard to overstate. Compile your code with an appropriate warning-level. Trying will weed out many errors, and point out ...
  • 18.2k
5 votes

LeetCode Daily Problem: Remove adjacent duplicated elements

I had to remove the non-standard <io.stream> and add <string.h> to get a declarations of ...
  • 63.2k
2 votes
Accepted

Function to skip characters

Compilation problems NULL isn't defined - either use the constant 0 or include ...
  • 63.2k
2 votes
Accepted

FizzBuzz solved by neural network

General Observations I can't comment on the ruby portion of the code because I don't know ruby. There are no classes in C but you could use a struct for the same purpose. Try to keep line length under ...
  • 19.9k
8 votes
Accepted

Rock Paper Scissors, Player vs Computer

Readability As mentioned, the width of the code spans through 112 characters, which is /not/ obviously too far. I recommend it not exceed 100 characters at most. Even that can be a little too much and ...
  • 1,528
6 votes

Rock Paper Scissors, Player vs Computer

Try to limit the line-width. Horizontal scrolling is death on readability. Commenting after includes what symbols you need it for is quite uncommon, as it just clutters things up and those comments ...
  • 18.2k

Top 50 recent answers are included