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.
6
votes
1answer
70 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 ...
11
votes
2answers
924 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 ...
-3
votes
0answers
16 views
Wilson Primes Calculator [on hold]
I've been trying to get my c code to calculate all wilson primes which are all numbers that answer the equation ((p-1)! + 1)/(p^2) with a whole number. I didn't think that there was a preexisting math ...
0
votes
0answers
9 views
Chip8 Emulator, issues with SDL2 audio [on hold]
The chip8 has a "sound timer" register. Whenever it is non-zero a beeping sound is made, it is decremented at 60hz whenever it is non-zero. I currently have a partially working sound implementation ...
3
votes
2answers
242 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 ...
-4
votes
0answers
16 views
How can I make the alphabets entered (through scanf) interpret as integers the way it's defined in an enum? Please have a look at the program below [on hold]
I am trying to make a C program for converting a given number in say base x, to base y. I chose to narrow it down upto base 20 (i.e. Base 2 to 20). When it comes to scanning a hexadecimal number (...
5
votes
1answer
38 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
0answers
25 views
Program to create an doubly-linked-list. Why does my code work? Am I missing something? [on hold]
I'm working through the exercises in the 'Pointers' chapter of 'Programming in C' by Kochan.
I have written a program that creates a doubly-linked-list. It first prints the values. It then proceeds ...
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
38 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
111 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
104 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 ...
-2
votes
0answers
20 views
Testing a C library without access to internals [closed]
I wrote a simple C library which generates OAuth authorization headers. It exposes a few methods for setting the parameters that are required from the user, such as the url, token, http method, etc; ...
4
votes
3answers
50 views
C Threadsafe Priority Queue O(log n) push, O(1) pop
I wrote this for an A* implementation:
(pqueue.c)
...
7
votes
2answers
124 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
75 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
32 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
47 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
46 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
137 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
33 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
501 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
60 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
110 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
45 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
23 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 ...
0
votes
1answer
40 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
42 views
1
vote
1answer
43 views
7
votes
3answers
404 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 ...
7
votes
2answers
132 views
Tensor product formula
Recently, I wanted 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,p}(...
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
419 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
41 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
23 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 ...
5
votes
3answers
122 views
Converting a decimal into a fraction
I have written a small program that converts a decimal number into a reduced fraction representation. I also designed this little program to be fairly robust, so that it can give the correct output ...
3
votes
2answers
97 views
Count the number of ways to obtain a sum, with consecutivity restriction
A cricketer can score 1, 2, 4 or 6 in a ball. Find in how many ways the player can score a total of "n" runs without hitting 3 consecutive boundaries. Note: Scoring 4 or 6 is considered as a boundary. ...
8
votes
1answer
71 views
Simple Lotto Game
I have developed a Lotto Game in C for my Assignment, it allows a user to enter one of the 6 menu options.
From the menu the user would be able to view the numbers they have chosen, another option ...
5
votes
0answers
32 views
Positioning a file pointer with MPI I/O
This toy code uses MPI I/O to read from a binary file.
It goes through reading:
an ASCII header
the first 10 doubles from an array of 100 ...
3
votes
1answer
72 views
3
votes
1answer
43 views
Pretty print a 2D matrix in C (numpy style)
Works for any 2D matrix represented by a 1D array. Comments and criticism welcome. Also wondering whether the code can be made shorter. It's really messy right now.
...
2
votes
1answer
81 views
-3
votes
0answers
40 views
'Terminated due to time out'. Need help in optimising my code
I am trying to implement dictionary. I would appreciate if you find the flaws in my code rather than changing whole logic.
Attaching the link of Problem
https://www.hackerrank.com/challenges/30-...
4
votes
2answers
100 views
Multi threaded text-based tetris game
I have decided to make a game of text-based Tetris in C.
At first I had no idea how to start so I settled for threads.
Each thread moves its own piece down the grid and all the main thread does is ...
6
votes
3answers
68 views
Four versions of a database-creation function with different error handling
I'm starting a new, small C project and would like to have the safest, cleanest and shortest error handling code possible.
Here is a comparison of different ways to handle errors in the same C ...
4
votes
2answers
38 views
Error-checking macro to jump to specified label given a failing statement
I'm starting a new C projet and I want to have the cleanest and shortest error checking code possible.
To that aim, I often use two things :
functions return 0,...
6
votes
1answer
111 views
C the sum of primes
The challenge is to calculate the sum of the first 1000 primes. The code applies a sieve thanks to past answer, here, and works but I wonder about the flexibility of this solution.
...