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

0
votes
2answers
21 views

Merge sorting a singly-linked list in C

I have this C implementation of the merge sort for sorting singly-linked lists: ...
3
votes
3answers
331 views

A simple Mastermind game in C

Any idea to write this code more smarter and shorter? I also expect your advice about general organisation of the code. Object of the Game In your version of Mastermind, the computer will be ...
0
votes
0answers
31 views

99 simple asynchronous bottles on the wall [on hold]

I have some basic code which registers functions, with given variables, to be executed after a certain time has elapsed. I will roll this code into my software project when it is ready. If it works it ...
10
votes
3answers
99 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 ...
3
votes
1answer
50 views

Insertion sort of a linked list

This is supposed to be efficient code, but it's taking much longer than what a normal insertion sort would take. I can't identify what's the problem with this insertion sort. Is there an ...
10
votes
1answer
86 views

Lexer for a language I'm working on

I've recently started working on making my own programming language and I just wrapped up its lexer. I'm too young to take any official training in C, compiler construction, or computer science so I'm ...
-1
votes
0answers
25 views

Odd behavior with MPI C [on hold]

I have a C code I'm trying to parallelize using MPI, and it shows some markedly weird behavior. Hoping someone can help. I have stripped this down to a minimal example that shows the behavior. There ...
-1
votes
0answers
23 views

Optimizing python code in benchmark game [on hold]

This is my first time on stackoverflow. I am learning python on my own. I have finished Zed Shaw's Learn Python the Hard Way. I was interested in optimizing python code and making it run faster. I was ...
3
votes
1answer
114 views

Find the first occurrence of a substring in a string

This is a simple version from the function strstr. It returns the address of the first occurrence of the substring s2 in s1. I want to know possible problems in the code, and how to improve it, in ...
1
vote
0answers
35 views

Improving a CGI Server in C

I made a simple CGI server in C, and I would like to have your opinion on my code quality. This would help me to improve. ...
0
votes
1answer
27 views

Implementation of the binary search algorithm [on hold]

This is my first implementation the binary search algorithm. I have tested it and so far it is okay. But I need an experienced eye to review the code and recommend best practices. ...
5
votes
1answer
106 views

Spell checker using trie

This program implements spell checking by loading a given dictionary file into a trie structure and comparing against a given text file: ...
4
votes
2answers
47 views

Tower of Hanoi (without recursion)

I came across an interesting method of solution for the Tower of Hanoi puzzle and wrote a short version of it as a programming exercise. The program produces the correct results but I have two ...
2
votes
1answer
44 views

Program for binary to decimal and vice versa

I started to learn C a week ago and this is my culminating program of what I've learned but I could use a few pointers. ...
2
votes
2answers
39 views

Intel® TinyCrypt: AES-128/CTR to encryption/decryption of 2D arrays

I need to encrypt/decrypt 2D arrays (double pointers) using AES-128/CTR using Intel TinyCrypt (written in C). The following are two helper methods to simplify the library usage. Any comments would be ...
7
votes
6answers
668 views

Standard way of reading file contents to a buffer

I have been trying to write a sample code block to read file contents into a buffer. I am assuming that: Code must be platform independent Should work in all cases(or report proper error) It should ...
8
votes
1answer
46 views

Automated Safety System Daemon in C89

Explanation This software is currently designed to: Spawn a daemon which controls and monitors multiple threads Create threads based on a 'list' of functions Monitor threads for operation Restart ...
7
votes
1answer
90 views

Cipher text using a 2D array

I have a simple program which ciphers text using a 2D array. You specify what letters to replace with what and it does it. I understand the code is very repetitive and that I should probably use ...
13
votes
2answers
1k views

Tetris in C, in 200 lines

I aimed at making fully functional (real) Tetris, in the shortest way possible in C. The result is a terminal game for Linux, that uses ncurses. I made it for my friend, who wanted to play it on his ...
4
votes
2answers
261 views

K&R 2-7 - Invert a bitfield from a number

This is my solution to the Exercise 2-7 of K&R C book. The assignment is: Write a function invert(x,p,n) that returns x ...
5
votes
1answer
52 views

Simple Version of Bunco Game

Any idea to write this code (fixable part) smarter? Note: Arrays, pointers, global value are not allowed to use. The game is played with 6 rounds. At the beginning, each player rolls one dice, with ...
3
votes
1answer
30 views

Exercise to create an insertString function to linked-list

Working from 'Programming in C' by Kochan. I'm on an exercise in the chapter 'Pointers'. This was the exercise: 'Write a function called insertEntry() to inset a ...
14
votes
5answers
1k views

Printing the PID of a program immediately before it runs

I need to know (for monitoring purposes) the PID of a program immediately before I start it. There could be multiple of the same program launched at the same time, so monitoring ...
2
votes
4answers
45 views

Counting the number of lines in a file

I'm easing back into C after several months of using Python and Matlab. Can anyone give me some pointers on how to improve my code's efficiency and readability? ...
1
vote
1answer
116 views

Function to find a substring within a string [closed]

I've just completed an exercise in which I had to create a program that searches for a string within another bigger string. If the substring exists then it is outputted to confirm and the starting ...
10
votes
2answers
1k views

Taking arbitrary length input in C

Instead of having to use something like char buf[100500] and hope that no possible user input could be longer than 100500 bytes, I decided to make the following ...
7
votes
3answers
109 views

Revised - Game of Fifteen

This is a revised version of a previous post. I attempted to address each aspect of the feedback provided. The key changes are as follows: Replace the deprecated ...
4
votes
3answers
54 views

C Threadsafe Priority Queue O(log n) push, O(1) pop

I wrote this for an A* implementation: (pqueue.c) ...
7
votes
2answers
130 views

Game of Fifteen - A Sliding Puzzle Game

Update: I addressed the changes and created an updated post. I'm reviewing C by working through the edX CS50 problem sets. This task was to implement Game of Fifteen aka 15 Puzzle. Project details ...
4
votes
2answers
83 views

Designing stack and queue from scratch in C

As a beginner and curious guy I'm interested in implementing data structures and algorithms from scratch. Here's my implementation of Stack and Queue, the most fundamental data structures. Are ...
7
votes
1answer
37 views

Implementing checksum add without carry in C

I need to write a function in C which performs a checksum using the rule "add without carry". As I understand it, the "add without carry" concept is equivalent to the bitxor operator and given that ...
0
votes
1answer
12 views

Efficient ways of looking for start-key and processing data

This question is a follow up from my previous question. I am working with some wireless communication in Arduino. 979797 is the address of the transmitter. I have written the following code to ...
2
votes
0answers
49 views

Better Brainfuck Interpreter in C

A little over a week ago I posted my basic brainfuck interpreter here. I have since improved the interpreter on all suggested points except two minor details. (reporting the position of parsing error, ...
2
votes
2answers
48 views

AVL tree insertion and deletion of nodes in C. 2.0

I asked a question yesterday, based on the answers to that question and some personal insights I was able to update the original code. which I am posting here to get reviewed. I also thought about ...
3
votes
2answers
140 views

AVL tree insertion and deletion of nodes in C

This is my implementation of AVL tree, it works fine. is there any thing that can be improved about addition and deletion procedures specifically when deleting the root, ...
2
votes
2answers
34 views

Dividing a long (arbitrary-precision) number by an integer

As part of a (slightly) larger program, I needed to write a function that could take an arbitrarily large number and divide it by a small number. In this program, I will be dividing this number ...
6
votes
3answers
504 views

Sort a binary file without loading it into memory or using a temporary file

I had a silly assignment: You are given a binary file FLOATS.DAT of unknown length, type float data has been written in it. Write a program which sorts the ...
8
votes
1answer
62 views

Process bytes and check for start key

I am working with some wireless communication in Arduino. My data will be wirelessly received like so: 97 97 97 ... ... 979797 is the address of the transmitter. ...
4
votes
1answer
119 views

New malloc implementation

I've written a new malloc implementation similar to dlmalloc and was hoping for feedback on it. The goals for this library are: ...
6
votes
2answers
46 views

Reading a line ending with a newline character from a file descriptor

I'm implementing a function that behaves like getline() which reads a line from file descriptor and returns the results without ...
1
vote
0answers
25 views

Generic Pairing Heap Performance

I have made a generic pairing heap library in C. Pairing heaps are one of the several heap variants with better asymptotic running times than standard binary heaps (others include Fibonacci heaps and ...
3
votes
3answers
62 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 ...
3
votes
1answer
43 views

Quick sort implementation

Please look the code below ...
1
vote
1answer
44 views

merge sort implementation 7

Please look at the above code ...
7
votes
3answers
410 views

Designing a binary tree structure from scratch in C

I'm a beginner and self learning programming students. While learning binary tree data types, for the sake of understanding graph theory and other interesting programming problems, I've writen the ...
8
votes
2answers
142 views

More efficient method to implement a tensor product formula

Recently, I would like to use C to implement the following formula: $$\mathbf S(u,v)=\sum_{r=i-p}^{i}\sum_{s=j-q}^{j}N_{r,p}(u)N_{s,q}(v)\mathbf P_{r,s}$$ Namely, $$ \left(N_{i-p,p}(u),\cdots,N_{i,...
28
votes
8answers
6k views

C program that reverses a string

As practice with the (ever so painful) C Strings I wrote a string reversal program. I am new to C, so I wanted to make sure that I am not using bad coding practices. It runs just fine (at least with ...
5
votes
2answers
425 views

Basic Brainfuck Interpreter in C

I have written a small Brainfuck interpreter in C. More recent version hosted here. I have found it very hard to test my interpreter because writing a program in Brainfuck is somewhat hard (or at ...
0
votes
1answer
44 views

Multi Producer - Single Consumer

I have written multi producer single consumer code with bounded buffer. Please review the code for any improvements or mistakes. ...
0
votes
0answers
24 views

Parallel Hillis-Steele Scan using CUDA

I'm learning CUDA (and C to some extent), and one of the algorithms that I am learning is the Hillis-Steele scan algorithm. I wrote a program that performs a simple scan with adding. After seeding ...