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.

learn more… | top users | synonyms

3
votes
1answer
15 views

Show the results of linked list operations in sequence

I'm working on a basic linked list programs. In this program I can insert elements at the beginning, at the middle (after one specific element) of the list and at the end. I also can delete a specific ...
3
votes
0answers
31 views

Multi-threaded webserver

Edit: I've been told my queue is not thread safe. Could I get some pointers on what I could do to fix it? Or an example of a thread safe queue? Can I get some help optimizing this webserver? Simple ...
4
votes
1answer
37 views

Pool allocator in C

This is an allocator that is used in replace of malloc if you do a lot of rapid, but small allocations on the heap. I wrote this for reducing system calls to improve performance. It works, but I've ...
0
votes
3answers
162 views

compute_ranks function

I've been working on optimizing such as loop unrolling, is there anything I can do to optimize this code to make it run faster/in less cycles? ...
1
vote
0answers
32 views

File manager project (creates and prints file)

I just finished my very simple and beginner-friendly C project and wanted to hear your thoughts and opinions about ways to improve it or something. ...
4
votes
3answers
164 views

Twiddle table computing

I'm trying to optimize this twiddle computing function: ...
0
votes
2answers
35 views

Adjacency list from scratch

Here is my code for implementing an adjacency list from scratch. I would like to get feedback from the experts for optimization. ...
2
votes
0answers
25 views

Linux performance using multi-threads (vs one thread) and ssh message

My server receives requests in one thread and responds in another. I am using thread pools of pthread-s for both receiving and sending. The performance is not that bad, however... When I am doing the ...
1
vote
1answer
46 views

Prime factorization - C

After learning prime factorization today, below is the C code written, ...
4
votes
1answer
49 views

Checking if CPU supports rdrand

My goal with this bit of code is to check if my processor supports rdrand and, if not, execute some other random number generating function. To check if ...
3
votes
2answers
35 views

Bubble sort code

I tried avoiding nested loops and usage of too many variables. This is up for review and comments. ...
2
votes
1answer
40 views

Beginning C BST implementation

I'd really appreciate if I could get some feedback on the following code with regard to security, efficiency and possible uncaught errors. Personally I feel the ...
3
votes
1answer
44 views

List abstraction using array

Following this reference, below is the list abstraction implementation using array, ...
0
votes
1answer
29 views

Quadratic probing and hashing - search for words in text files

I created a program for a college class. After I got it working, I wanted to improve it. As a beginner, it is probably a mess. Description It uses a HashFunction ...
2
votes
1answer
30 views

Securely Delete All Drive Data

When giving away or selling a PC, one should be careful not to send personal data with it. I'm in such a situation and was using dd if=/dev/urandom of=/dev/sdb bs=8M...
1
vote
3answers
57 views

C strlcat implementation

I have to reproduce some basic functions in C and one of them is strlcat. After reading the man and testing the strlcat from <bsd/string.h> library, I wrote ...
4
votes
2answers
62 views

Red light, green light… kinda

For an assignment I had to create a client and a server that communicate over a well known FIFO. The server is required to use three threads to serve the client, managed by a semaphore. The code was ...
3
votes
1answer
56 views

Win32/C: Notepad wrapper that automatically converts Unix line endings to Windows line endings

At my work we're dealing with a lot of PHP files written by a third-party company and sometimes we want to "quickly look at" these files in Notepad rather than having to open up a full IDE. The ...
3
votes
1answer
48 views

Waiting for input with timeout

When my program begins, I want to allow the user to hit a key to enter debug mode for one of the modules. Many of the solutions (involving alarm(), in particular) ...
-6
votes
0answers
34 views

Linux performance drawback when networking from two pthreads [closed]

my server receives requests in one thread and responds in another. I am using thread pools of pthread-s for both receiving and sending. The performance is not that bad, however... When I am doing the ...
3
votes
1answer
54 views

Concatenate variable number of strings

I am learning C on my own. This is not an assignment. I am trying to implement a function that takes a variable numbers of strings and concatenate them in a new string. It works, but I feel it is not ...
5
votes
1answer
26 views

Short header file for safe CLI input handling in C

Proper input handling is a pain in the butt in C, so as part of a project of mine, this header is used to handle reoccurring command line input tasks such as input loops, reading lines and tokenizing ...
1
vote
0answers
29 views

A-Eye: Analysing Eye tracking Data

I'd appreciate your advice. data file: https://drive.google.com/open?id=0B_UEM0TEmA_yeHJBZ0dzbV9Ca2c ...
1
vote
2answers
65 views

Binary search-like algorithm to find local peak

Please help me improve my coding style. ...
4
votes
1answer
29 views

String tokenizing with arbitrary token count in C

I am building a small program for input handling so I can conveniently parse lines and tokenize strings. The token handling works right now but I have to malloc a lot in the main() to make it work. ...
1
vote
1answer
33 views

Select comparison function for sorting based on type information

So I'm working on a patch for the python interpreter where you go through the list and look at the types of the elements and try to use optimized special-case comparison functions that are much ...
5
votes
4answers
114 views

Factorials, loops, break and professional code

The program below correctly calculates factorials, until the limit for an unsigned long long integer is exceeded. My question has to do with loops and exiting ...
3
votes
2answers
44 views

Config file to struct in C

I have a struct OPTS which contains a few chars and char[]s. I also have a file opts.cnf ...
6
votes
1answer
98 views

Reference Counting in C99

(I created a GitHub repository; there are few improvements as suggested by other users in the comments) As we know, C99 has no garbage collector. To address the problem of manually deallocate objects ...
4
votes
1answer
65 views

Using bitwise operators with (unsigned long) instead of bitfields

Here is my solution to Programming Exercise 15-7 from Stephen Prata's C Primer Plus, 6th Edition. This problem asks the reader to: 15-7 Write a program with the same behavior as described in ...
7
votes
4answers
117 views

Calculate the number of palindrome numbers in the given ranges

I've written a program that calculates all of the palindrome numbers in the given range, but the code is slightly slower than needed. I've tried to improve algorithmic complexity to the best of my ...
10
votes
3answers
473 views

Counting the number of “on” bits in an int

Here is some code I wrote as a solution to Programming Exercise 15.3 in Stephen Prata's C Primer Plus, 6th Edition. It is probably worth pointing out that the title of the chapter is Bit Fiddling. The ...
1
vote
1answer
59 views

K&R 2.6 Exercise setbits(x,p,n,y) function

Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position <...
5
votes
1answer
711 views

C program circular array rotation

I'm trying to solve a Hackerrank problem where you perform k array[n] rotations, and at the end, ask for ...
5
votes
2answers
182 views

20×20 Game of Life in C

I am new to C, but have experience with Python and R. The following code implements the Game of Life and represents my first finger exercise in C. I would like to have some feedback regarding the ...
6
votes
2answers
375 views

Small part of an INI parser

I know there are probably thousands of INI parser implementations in C. Nevertheless I want to implement one to learn the art of parsing grammar. I just wrote a small piece of the INI parser and ...
4
votes
1answer
44 views

Simple file server for GET requests

I recently made this simple server in C for Linux systems and was wanting to get another set of eyes on it for a review of the design. I am new to socket programming and used a textbook from school to ...
-6
votes
0answers
85 views

Stack in C and Python

I just finished writing Stack in C and Python and I want someone to review it for bad code, missing features and possible improvements. Here is the C code: ...
6
votes
1answer
233 views

Brainfuck compiler with tcc backend

I wrote simple compiler for Brainfuck with tcc backend (dont ask for assembler/assembly code generator!). It's output runs incredibly slow. Even Hello World program takes a LOOONG while to execute. I ...
1
vote
1answer
44 views

Simulating dynamic polymorphism in C

This code snippet is a research attempt to find means for dealing with dynamic polymorphism (in C): two or more related "classes" share a common interface. Here is my best shot: ...
8
votes
3answers
212 views

A program to represent a coin amount using the smallest number of coins

Recently, I was learning about greedy algorithms. One example that was given was an algorithm for exchanging a given money amount using the smallest number of coins. After the lecture, I wrote a C ...
91
votes
17answers
12k 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 ...
3
votes
1answer
65 views

Sum of Absolute Differences algorithm implementation

Those unfamiliar with that algorithm can have a deeper look here, in a few words, there are two arrays where you subtract each element ar1[0][0]-ar2[0][0] and add ...
2
votes
2answers
64 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. ...
3
votes
1answer
40 views

Basic memory pool, alignment, thread safety

Mainly for practicing purposes, I'm trying to implement a simple, yet efficient memory pool. It's basically a linked list that is able to grow, with fixed sized members. Each node has a flag if it's ...
6
votes
2answers
979 views

Very simple stack in C

I'm starting to learn C and thought it would be a good idea to try and implement some data structures. I started with a very simple stack and would like to hear some opinions. Stack.c ...
8
votes
3answers
241 views

Removing multiple slashes from path

I have been trying to write a sample code block to remove multiple backward or forward slashes from a path (e.g. //a//b should be ...
2
votes
2answers
35 views

Inserting into a binary search tree in C

I am in the process of refactoring this simple binary search tree code responsible for adding new values: ...
1
vote
2answers
101 views

Draw a centered circle

I've written this program that, renders a circle in the middle of the screen. It's been written in a very elementary way. Any suggestions on principles or techniques? Or any more optimal or efficient ...
3
votes
1answer
86 views

Convert hex to base64, part 2

Original question Reimplemented solution following JS1's answer. Changed bit string hack to bitwise operations to get the corresponding base64 index values. ...