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
0answers
17 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
10 views

Parallel Sum 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. I don't really ...
5
votes
2answers
75 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 ...
2
votes
1answer
55 views

Dynamic Programming: Optimal Solution for Number of Ways to get n

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
62 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 ...
4
votes
0answers
20 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
59 views
0
votes
0answers
12 views

Split a text file into multiple files at keywords [on hold]

This program only splits the inputted text file in half but I can do it according to line number as well. I need to split according to a word. I have over 200 books in a text file i want to split the ...
3
votes
1answer
33 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
67 views

Linked list C code

This is a toy version of the code I really want to write: ...
-3
votes
0answers
35 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
89 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
63 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
34 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
99 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
144 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
129 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
37 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
148 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 ...
0
votes
4answers
141 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
210 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
28 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: ...
14
votes
9answers
2k views

Given three numbers, find the second greatest of them

I've just coded this for my country's programming Olympiad. I want to know if this method is a good approach in terms of readability and performance. I would also like to know how to improve it. Note:...
3
votes
1answer
40 views

Simple program to insert values in a linked list

I tried to write a simple program using linked list where I just insert the value stored in every node and then through a function print the values. This is the code: ...
2
votes
1answer
35 views

Segment tree challenge

Here is my implementation of a segment tree with a sample driver file (I didn't make an update function because I didn't need it for what I was doing). I'm a huge fan of geeksforgeeks, but I do not ...
4
votes
1answer
63 views

Max difference between two array elements

Can I get feedback on below code? Problem statement is Maximum difference between two elements such that larger element appears after the smaller number Would this solution be still considered O(n) ...
8
votes
2answers
41 views

My own snprintf implementation in C

I decided to make my own version of snprintf in C. I intentionally changed some things though. My version guarantees the buffer printed to will be null-terminated, ...
7
votes
2answers
122 views

Checking that a password contains a '$', a digit, and an uppercase letter

I have this code, which reads in a string password from the user and checks if it has a dollar sign $, a number, and an upper case letter. If it has all three, it ...
0
votes
2answers
63 views

Fizzbuzz in C for console

I imagine I get a minuscule performance improvement by doing the %3 as a branch off the %5 rather than the other way round or as an if '%15'. Am I correct about that? (I know there is no practical ...
5
votes
3answers
512 views

Snake game in C for Linux console

Please help me improve this code. Move snake using : a w s d. (My compiler doesn't support initialization of index variables inside loops, so please ignore this part) ...
5
votes
2answers
314 views

itoa base function in C

This is a function that converts an integer value to a null-terminated string using the specified base and stores the result in a char array that I must allocate (...
4
votes
2answers
95 views
6
votes
3answers
121 views

Pausing a loop with a Raspberry Pi 3

I am trying to perform a loop and then stop the loop when the last line of code in the if statement is printed to screen saving on CPU cycles. I want to start a <...
2
votes
1answer
46 views

Recursive spinlock for C using ASM, revision #1

Precursor for this revision here in code-review: Recursive spinlock for C using ASM Improvements have been made thanks to forsvarir. Now I am trying to optimize this lock so it becomes more ...
3
votes
0answers
57 views

Reduce encoded length of UTF-8 encoded Ruby string in C extension

I'm writing a Ruby extension in C. It's a string processing module working on UTF-8 encoded strings only. One method, full_width_to_ascii!, converts full width ...
4
votes
2answers
63 views

Processing trip route table in C

In fact, this is a group assignment for our C programming lesson, but seeking help from others is not considered cheating. The goal of the following code is to: Sort the data in ...
2
votes
2answers
32 views

Small Poker program rewrite

I had already put up code for review a small poker program but I have rewrote it utilizing a more appropriate data structure. How would I compare Poker hands accordingly? Full source repo ...
1
vote
2answers
28 views

Sorting structures lexicographically

I am swapping structure lexicographically by name. Is there any way to improve the code when the structure entries are heavy. Here is the code ...
5
votes
1answer
134 views

Printing fizzy lines

Challenge Given a test case print out a FizzBuzz Series. Specifications The first argument is a path to a file. Each line includes a test case. Each test case is comprised of three spaced ...
1
vote
3answers
86 views

Recursive function that reverse the words in a string

I have been working on a problem that asks me to a write recursive function that can reverse the words in a string. For example if the string is "cat is running", then the result should be "running is ...
3
votes
1answer
108 views

Finding the prime factors of a positive number

I have an assignment to write on the standard output the prime factors of a positive number displayed in ascending order and separated by '*'. My code works, but I need help reviewing it before I ...
8
votes
1answer
62 views

Longest lines using priority queue

Inspired by a comment on this question, I thought I'd exercise my C skills by implementing something like it using a priority queue. The idea is to be able to invoke the program like this: ./...
8
votes
2answers
808 views

C the large print

This is the Longest lines challenge from CodeEval: Challenge Write a program which reads a file and outputs a specified number of lines, sorted on length in descending order. ...
4
votes
1answer
45 views

Bottom up (iterative) mergesort in C

I have this C implementation of the bottom-up (iterative) mergesort: mergesort.h: ...
1
vote
1answer
41 views

Parsing and executing a simple shell script

I'm writing a simple shell and want to parse and execute a simple shell script. ...
7
votes
3answers
2k views

Implementing atoi() in C

I was given a school assignment to implement atoi(). Please review my code. ...
7
votes
4answers
906 views

No more filthy words

Challenge Given a list of words mixed with extra symbols. Write a program that will clean up the words from extra numbers and symbols. Specifications The first argument is a path to a file. ...
4
votes
5answers
124 views

Test four int of commonality in the lower four bits

The four parameters a, b, c and d can be ...
11
votes
2answers
1k views

Tic Tac Toe vs PC

Please help me reduce its complexity and maybe optimize it a little bit more. ...
3
votes
0answers
72 views

CUDA program that emulates a kind of cellular automata slower on the GPU than on the CPU

I'm a very new to CUDA, so I'm still trying to understand how to make the best use of the GPU. I've ported a C algorithm to it. This algorithm works by loading the memory with an initial input, then ...