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.
1
vote
0answers
16 views
8 shades of grey (sliding puzzle)
I've written a smaller version of 15 puzzle in C, using OpenGL 3.3 and freeglut. I've found a place you can play it online to get familiar. I'm new to OpenGL, so I have no idea if I'm doing this in ...
1
vote
1answer
34 views
Storing and processing large amount of data in C
How can I efficiently store and process data for this problem?
Problem Statement
We have two arrays a and b of length N, initially all values equals to zero. We have Q operation. Let's define ...
2
votes
1answer
21 views
Unreliable shared memory circular buffer with read-only consumer
This code is slightly platform dependent but should be pretty easy to port. The goal with this code was to create a circular buffer where the consumer could be limited to read-only access of the ...
2
votes
0answers
18 views
Vigenère cipher 2: electric boogaloo
The following program is an updated version of this question, an implementation of the Vigenere cipher in C. It has been updated to take input from stdin and pipes, ...
0
votes
0answers
14 views
Multiple reader threads and multiple writer threads synchronization [on hold]
Let's say there are multiple reader thread and multiple writer thread for maximize throughput. The writer will be accessing from device and put it to buffer. The reader will be reading buffer then ...
7
votes
2answers
39 views
Printing the days of the week for every day this year
@chux pointed out that my attempted solution contained several problems. Since I screwed that up so badly, I figure that I should put my revised solution up for review.
...
3
votes
1answer
28 views
Real-Time MP/SC Lock Free Ring
This is (the significant) part of an implementation of a logging mechanism for recording events in a real-time control system. The basic requirements are:
No dynamic memory on either side ...
3
votes
2answers
45 views
Creating a linked list of n length
I wrote this working code to create a linked list of a given length and print each node's values.
...
2
votes
2answers
33 views
Print the length of words as a vertical histogram
I thought I'd give it a shot. What I came up with is from a culmination of my last two submissions, incorporating most of the feedback from this community, including better naming of variables, ...
7
votes
4answers
699 views
Shift positive integers to the left
I would like to write a function in C that turns all negative values into zeros then shifts the positive numbers to the beginning of the array, maintaining the order of the positive integers in the ...
5
votes
5answers
290 views
Using functions to separate code for Fahrenheit to celsius conversion
I'm relatively new to programming, and I've been wondering about a problem such as this. How can I think about decomposing the code into its constituent functions? I went the simplest route I could, ...
4
votes
1answer
180 views
Vigenère cipher in C
For my second major project in C, I decided to write an implementation of the Vigenère cipher in C.
My program uses command line options (optarg) and can read from both a file or from a string ...
4
votes
1answer
23 views
Print the frequency of characters as a horizontal histogram
Well, I've used some of the feedback from my last posting to improve how I wrote this program. Mainly using the void parameter in main, initializing my int array to zero without using a for-loop, and ...
5
votes
3answers
67 views
Print the length of words as input to a histogram with horizontal bars
It works, but I'm sure there's a lot of improvement I could make here. I didn't try to get it to work for words over 10 characters in length, and I also didn't want to use built in properties like ...
3
votes
2answers
103 views
Self-written Mutex for 2+ Threads
I have written the following code, and so far in all my tests it seems as if I have written a working Mutex for my 4 Threads, but I would like to get someone else's opinion on the validity of my ...
1
vote
0answers
36 views
A* pathfinder in C
Now I have this implementation of A*. Basically it is the same as the Dijkstra's algorithm in my previous post, yet I bothered to make it more cohesive by making functions for handling all the state ...
5
votes
2answers
173 views
Print output one word per line - K&R Exercise 1-12
When writing this code I found myself getting more and more complex. When I got to the solution I trimmed the excess parts I'd thought I needed from before, but didn't actually need. The example of ...
7
votes
2answers
65 views
Merge Sort without pointers in C
As part of an online course exercise, I was supposed to implement Merge Sort in C. Pointers were still not discussed prior to this exercise, so I have to work with arrays. Memory efficiency is not ...
4
votes
1answer
47 views
Dijkstra's shortest path algorithm in C
Now I have this C implementation of the famous algorithm:
dijkstra.h:
...
2
votes
1answer
46 views
Circular array list in C
Now I have this circular array-based list in C. Circularity allows pushing/popping to the both ends of the list in constant amortized time. Inserting/removing at random locations runs in linear time, ...
4
votes
2answers
60 views
Vigenere's Cipher in C
I have updated the code and the program now works as it should. If you could critique my code that would be great. I am new to C so I guess I will have made some rookie error :)
...
3
votes
3answers
54 views
Displaying days of the week for all of 2015
This program is supposed to determine the day of the week for 2015. Could someone tell me how I could shorten my code?
...
3
votes
1answer
38 views
d-ary heap in C
Now I have this d-ary heap data structure. Note that for d = 2 this is a binary heap. The client programmer specifies the value ...
4
votes
1answer
42 views
Unordered (hash) map for C
I am still working on basic data structures for C. Now I came up with a hash map:
unordered_map.h:
...
6
votes
2answers
107 views
Number converter between bases
I just wrote a utility program in C that converts numbers of different bases to 'standard' well-known bases (hex, dec, oct, bin). I called it repnum, short for ...
3
votes
1answer
46 views
Ordered map for C using AVL tree
I was in the mood for some data structures and I decided to code up an ordered map using AVL tree. I will post only map.h and ...
6
votes
2answers
97 views
Reverse engineering Darkstone game archives
Reverse engineering old games is something I do every now and then. This time, I took a shot at this old RPG called Darkstone.
The bulk of the game's data is stored in archive files with the ...
10
votes
2answers
62 views
Roguelike-ish template game
I have created a simple program that is supposed to be the core of a roguelike game. The program uses ncurses, and all that is supposed to happen is you choose a race and class, then choose an arena. ...
8
votes
3answers
95 views
Calculating longest increasing sub-sequence recursively
I have trouble understanding recursion, so I'm trying to implement algorithms using it. I wrote this code that calculates the length of the longest increasing sub-sequence. How can I improve this?
...
2
votes
1answer
31 views
Menu driven program to represent polynomials as a data structure using arrays
Write a menu-driven program to represent Polynomials as a data
structure using arrays and write functions to add, subtract and
multiply two polynomials; multiply a polynomial with a constant, ...
5
votes
1answer
83 views
C implementation of a string
As C does not have a native string type, I decided to try making a similar type. It's not perfect by any means, so I was coming here to see what I could do to ...
4
votes
1answer
56 views
Generic vector implementation in C using macros
I while ago I experimented with macros in C and came up with the idea of implementing a generic vector library using macros.
This code uses the non standard typeof ...
5
votes
1answer
61 views
Implementation of Symbol Table in C
Following is my code for implementing basic symbol table in C. Please review my code and tell where I can improve my program.
...
5
votes
2answers
156 views
Finding the order of sorting of an array
I am finding the order of sorting of an array. The code works but can it be made better especially the return values of the function findSortOrder.
...
1
vote
2answers
42 views
Finding difference between adjacent integers in an array - recursive Implementation
I'm trying to do a recursive implementation of the problem mentioned below.
The code works, and takes care of a corner case with only 1 element in array (in which case I should return ...
2
votes
3answers
138 views
Printing a text rectangle
I'm starting C as my first language and am just under halfway done the book I'm using. However, I commonly hear about 'bad' programmers and 'bad' code whenever I encounter any sort of programming ...
4
votes
3answers
37 views
Balanced expression checker
This program detects whether an expression is balanced or not. I would like to know how I can make this more efficient.
...
10
votes
0answers
88 views
C SIMD Matrix Multiplication
I recently started toying with SIMD and came up with the following code for matrix multiplication. I would greatly appreciate if someone with more experience with these things could tell me how far ...
1
vote
0answers
34 views
Lock-free ordered singly linked-list behaves unpredictably [closed]
I wrote an algorithm for lock-free singly ordered list, that uses only one pointer mark to function - kind of novelty. However it behaves strangely, that is under more pressure > 20 threads it breaks, ...
12
votes
5answers
1k views
Credit card validation
I started following Harvard's CS50 (Introduction to Computer Science) on edX, and as part of their Hacker edition set 1 was the following assignment:
I am supposed to write a program (in C), that ...
5
votes
2answers
64 views
File of words to a linked-list of words
I'd like to get a review for the function build_list() which reads a file containing words (separated by spaces) and returns a linked-list of words:
...
6
votes
3answers
82 views
Comparing three O(n^2) search algorithms in C
I'm currently taking Harvard's CS50 course via EdEx.org, and we're learning about sorting algorithms. More specifically, we're studying bubble, insertion, selection, and merge sorts.
Just for kicks ...
5
votes
1answer
27 views
Distribute an array of numbers equally
The user will input two numbers, say 19 and 5. We need to equally divide 19 equally into 5 groups and output the start index and the end index of each group (using zero-based indexes). Example:
...
7
votes
2answers
66 views
Minimum number of coins problem using dynamic programming - follow up
I previously posted a code here. It turns out that the code is not following the correct dynamic programming principles and instead it was based on a greedy approach. Hence, I started again, keeping ...
10
votes
3answers
574 views
Coin Change: Minimum number of coins
Problem:
You are given n types of coin denominations of values \$v(1) < v(2) < ... < v(n)\$ (all integers). Assume \$v(1) = 1\$, so you can always make change for any amount of money ...
10
votes
2answers
162 views
Sending an SMS message in C
Recently I've been fiddling with the idea of sending a text message using C. Looking at a few options, I thought that using libcurl to send an SMTP email using TLS for some security would be the best ...
5
votes
5answers
380 views
Shorthand expansion exercise from K & R C (ex 3-3)
I have written a function to take some shorthand input and expand it into the full form, for example a-z0-9 becomes abcd...789. I added protection from buffer overflow exploits (knocks on wood), and ...
11
votes
1answer
61 views
Callback in Linux kernel driver in order to hide device's low-level protocol
I'm am writing a Linux kernel driver for HD44780 LCDs connected via I2C bus. In my last change I tried to decouple low-level code (which talks to the device via I2C) from device's logic (printing ...
7
votes
2answers
56 views
Game of Runes: revised version
I have created a game called Runes in C. It is similar to Chess, but has a bigger board and different pieces. I would like to know how I can improve the code, for example, with user interface ...
7
votes
1answer
50 views
Game of Runes: a similar concept to chess
I have created a game called 'runes' in C. It is similar to Chess, but has a bigger board and different pieces. I would like to know how I can improve the code, for example, by adding proper error ...