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.
8
votes
2answers
204 views
Lexer for C in Python
I am currently taking a compilers course where we are designing a compiler for C- (which is a subset of C). Our first step was the lexer and I have written that but I believe that it is not very ...
5
votes
2answers
41 views
Python code to run a C program that calculates whether points are in the mandelbrot set
This is part of a project to explore the Mandelbrot set. The code to graphically navigate the complex plane and allow the user to adjust the colormap and number of iterations is all written in Python, ...
10
votes
4answers
94 views
ASCII art generator in C
I have written an ASCII art generator library. I was practicing data abstraction and code abstraction and I wanted to know if there is something that can be improved.
File tree:
...
-6
votes
0answers
40 views
Write a C Function [closed]
The Question is:
Write a function which takes a sorted list and groups equal values into a group(a list) and therefore returns a list of lists
example:
...
4
votes
0answers
59 views
Learning OpenMP+MPI: Feedback and comments on Gauss-Seidel+SOR
I am learning OpenMP+MPI hybrid programming. As an example I have chosen Gauss-Seidel+SOR. My implementation uses MPI_THREAD_FUNNELED style hybrid programming, ...
4
votes
4answers
93 views
10
votes
4answers
209 views
Writing computer generated music to a .wav file in C - follow-up
See the previous and initial iteration.
Now I have refactored the code according to many suggestions made in the first iteration.
What's new:
I attempted to deal with endianness. I have zero ...
26
votes
5answers
2k views
Writing computer generated music to a .wav file in C
See the next iteration.
I wrote this simple C program for writing computer generated music to a WAV file over three years ago. I refactored it a little, but it does not look good to me. Any ...
-2
votes
0answers
14 views
Segmentation Fault encountered [closed]
Expected Output:- b
Problem Encountered:- Segmentation Fault
#include<stdio.h>
void main()
{
char *k = "ayqm";
printf("%c", ++*(k++));
}
-2
votes
0answers
15 views
A few problems in my shoot 'em up game code [closed]
I have been trying to code a shoot 'em up game and so far i noticed a few problems when i run the code.
Problems i see include a few light red circles and bullets appearing at the start when it ...
3
votes
1answer
87 views
Re-implementing memcpy
I have written an implementation of memcpy function and I want to know how good is it and if it gets the most out of the processor capabilities or not.
The reason ...
4
votes
3answers
78 views
State machine implementation
I have written a simple state machine. Comments and feedback are welcome.
...
2
votes
2answers
39 views
K&R atoi() variation
I'm currently learning C with The C Programming Language by K&R and this is my current exercise:
Rewrite appropriate programs from earlier chapters and exercises with pointers instead of array ...
2
votes
0answers
24 views
HTTP request extraction
The following code is intended to extract HTTP request line and store method request-URI and HTTP-Version respectfully in arrays method, target, and version.
I am quite not happy with the design at ...
-1
votes
0answers
24 views
5
votes
3answers
64 views
Cryptoanalysis of Vigenere-ciphered text with Kasiski test
I am creating a program that will analyse encrypted text using Kasiski examination in order to find possible key length:
...
3
votes
1answer
36 views
Length prefixed strings in C [closed]
In want to implement length prefixed strings in C (not null terminated), with some idiosyncrasies: malloc is prohibited, memory efficiency is important, each string (except for literal-backed ones) is ...
3
votes
2answers
47 views
C - K&R getint() variation
I'm currently learning C with "The C Programming Language" by K&R. At the moment I'm at the chapter about pointers (since I come from Java, they are new to me). In the book is an example code for ...
5
votes
2answers
383 views
Program that tells if a date is valid in C
I'm reading a book about C programming, at the end of each chapter it has some training exercise and one of them was to make a program that tells if a date is valid or not, the code below is what I ...
8
votes
1answer
122 views
Assembler for the HACK assembly language
Here's my assembler for the HACK assembly language, part of the Nand2Tetris course. I'd really appreciate any comments/criticism/help!
If you want to know what input and output files should look ...
-1
votes
0answers
41 views
5
votes
4answers
141 views
Utility functions for a linked list
I have written code to add a node to the head of the list. Criticisms and feedback are welcome.
...
0
votes
4answers
69 views
Evaluating a tic-tac-toe board using a C-style for loop in Rust
I program in C, and it's my favourite language. I've recently found Rust. I like their ideas. Sometimes looks like a weird mixture of C++ and Haskell, but overall it looks nice.
The ...
4
votes
1answer
53 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 ...
3
votes
3answers
150 views
Storing and processing large arrays to compute dot products
Problem Statement (from HackerRank)
We have two arrays \$a\$ and \$b\$ of length \$N\$, initially all values equals to
zero. We have \$Q\$ operations. Let's define three types of operations on
...
2
votes
1answer
29 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 ...
4
votes
1answer
59 views
Vigenère cipher 2
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, ...
7
votes
2answers
42 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
36 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 ...
4
votes
2answers
55 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
36 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
709 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
303 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
208 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 ...
5
votes
1answer
29 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
75 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
104 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
38 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
182 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
75 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
51 views
Dijkstra's shortest path algorithm in C
Now I have this C implementation of the famous algorithm:
dijkstra.h:
...
2
votes
1answer
48 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
67 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
55 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
111 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
103 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
63 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. ...