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
0answers
20 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
28 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
35 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
110 views

Function to find a substring within a string [on hold]

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
101 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
18 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
43 views

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

I wrote this for an A* implementation: (pqueue.c) ...
7
votes
2answers
122 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

Quick sort implementation

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

merge sort implementation 7

Please look at the above code ...
7
votes
3answers
403 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
131 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
96 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

Linked list C code

This is a toy version of the code I really want to write: ...
-3
votes
0answers
39 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. ...
2
votes
2answers
148 views

How do I write my multithreading code correctly so that it is faster than a single thread?

I have the following code that I am trying to optimize. I am running it on a Linux machine with 24 cores. I thought I could use multithreading to make it faster, but it's somehow making it way slower ...
3
votes
1answer
134 views

A small generic array in C

The generic arrays in C I found on the net used either of these methods: The preprocesser with #define and #include (a lot of ...
4
votes
1answer
42 views

Polymorphic pointers-to-functions whose parameters are void pointers as arguments in C

My question is about this sort of table that's simplified here. Often, I find myself putting this element, (int (*)(const void *, const void *))&strcmp for <...
10
votes
2answers
153 views

Dijkstra's algorithm for computing the GCD of two integers, translated from C to x86 assembly

This is the x86 version of a C file assignment (I have included both). We were to convert the C code to assembly. I am rather new at assembly and would really appreciate suggestions and help for ...
1
vote
4answers
144 views

Program to display array elements in the ascending order of number of factors each element has

Input: 1000 23 100 26 32 Output: 23 26 32 100 1000 Since 23 has '2' factors and 26 has '4' factors and 32 has '6' ...
8
votes
3answers
216 views

Check if 2 rectangles fit in another one, given their length and height

I was very intrigued with the manner to solve this problem. The program needs to know if 2 rectangles fit in another one, considering the lines of the 2 rectangles are always parallel to the other one'...
1
vote
0answers
29 views

Tab completion for custom shell

The purpose of the code is to enable tab completion for a custom shell I'm writing. The target OSes are Linux and OpenBSD. I had to make a conditional include that I hope is correct: ...