Questions tagged [c]

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.

Filter by
Sorted by
Tagged with
0
votes
1answer
41 views

Clock in C language

Ok, so here's the code: Please, comment if there are mistakes ...
1
vote
0answers
32 views

Counting Cram game positions in C

This code counts the number of possible positions in the game of Cram on a mxn board. EDIT 1: In the original question I mistakenly mentioned that this number is ...
1
vote
1answer
36 views

Server hosting single page site using TCP sockets in C

I have written a simple server to host my page and CSS (CSS file is 22KB). Using sockets and TCP. Can any one please review it and give feedback on how can I make my server reliable using TCP and ...
0
votes
0answers
18 views

Is this a disadvantage of using sleep() or a problem with outputting the count every iteration? (Child process doesn't execute as far as expected) [closed]

Just a real quick question. Could someone either confirm or correct my theory as to why my child process does not execute as far as I would think? Given what I have, I would expect the child to reach ...
2
votes
1answer
70 views

Writing an x64 Code Emitter to eventually make a full fledged Assembler like NASM

As the title suggests, I'm writing an x64 Code Emitter. Right now I've only encoded 1 instruction (The add instruction). I want to know if this API can be improved at all. This is how you I use it. <...
7
votes
2answers
137 views

2D Maze Game with Monsters

Introduction I've started to learn C programming a bit and wanted to create a simple 2D console game. Let me first introduce you to the game level/map structure: ...
4
votes
2answers
963 views

CSV file reader

Hi, I asked this question over on stack overflow. However, they closed the thread and suggested to ask it on code review. So here I am :) The code below is an updated version of my original code, ...
1
vote
2answers
69 views

Counting and printing sentences and words

Any sequence of characters starting with a non-whitespace character and ending with any of the following is considered to be a sentence by this program :- a full stop ...
7
votes
2answers
254 views

Hack machine language assembler as required for project 6 of Nand2Tetris

This is the implementation of the Assembler required to parse source code written in the Hack Machine Language and output it to a 16-bit binary file. After writing one go in Swift, I decided I wanted ...
5
votes
4answers
1k views

Minimum of two floating-point numbers

I'm learning C and I just had the exercise to write a function that checks for the lower one of two floating-points. So I thought, I either could use pointer and also return the pointer of the lower ...
8
votes
2answers
538 views

Task manager with dependencies

todo(1) is a program that lists the next tasks in decreasing order of urgency (most urgent tasks first). "Next" tasks are those which are not blocked by a task it depends that is still not ...
3
votes
1answer
48 views

README reader program

A little program I wrote because I had nothing better to do: a README reader. Run readme to print the first lines of the README file (or README.md or README.org...) ...
-1
votes
2answers
72 views

Find the matrix row having the largest sum

...
0
votes
3answers
69 views

Printing out the squares of n numbers in C

I am trying to print out the squares of n numbers, n which is a value retrieved from the user. I want to know if there is a better way to do this: ...
1
vote
1answer
71 views

Providing a C interface to a 'Region' map

I decided using a C++ map or unordered_map is the most appropriate option to store 'Regions' where which can be loaded in ...
1
vote
1answer
31 views

Store all most used directories and query for most used directories containing a string

This is an implementation of zoxide in C, it uses a shell alias to cd between directories it stores(as csv in form of <count,path>) or when the directory is ...
5
votes
3answers
196 views

A priority based timer using priority queue

I am trying to implement a priority-based timer where certain events are fired out based on their expiry and the priority. So if there are 3 timers with the following expiry time and priorities ...
2
votes
1answer
104 views

Robin Hood hashing

This is an implementation of a "string to int" hash table with Robin Hood hashing. I have tested it as thoroughly as I could. It appears to have no bugs/leaks. I would appreciate any ...
1
vote
1answer
19 views

Setting Wallpaper with Xlib and ImageMagick cli

This program reads raw pixels from the pipe/stdin in a loop and set the root window background. ...
3
votes
1answer
47 views

Matlab vs C: Tensorproduct or Vec-trick (multiple times)

I am searching for a more efficient way to calculate the so called vec-trick used in Tensor algebra, see Wikipedia. Introduction: Suppose you have a matrix vector multiplication, where a matrix C ...
0
votes
4answers
198 views

Find the next prime at/after a given integer

I created a function that returns the next prime number greater or equal to the number given as an argument. My code works well, but I find it is very slow. The test suite take almost 60s and I want ...
2
votes
2answers
150 views

Fahrenheit to Celsius table temperature converter in C

I am brand new to programming in C. I am following along with the book "The C Programming Language, Second Edition." I am making my own modifications to the example code presented in the ...
1
vote
1answer
43 views

Validate Empty Sudoku: Multi-Threaded Solution

The problem is that we have an unsolved sudoku board, and we want to validate it, we need to check each column, row and sub-square. Here we represent a empty cell with -1. My idea was to create a ...
3
votes
1answer
72 views

Efficient (a XOR (b+1)) known (a XOR b) in C for the ChaCha algorithm

I'm currently trying to improve my ChaCha algorithm implementation. Here's the my code (written in C): ...
1
vote
2answers
78 views

Function to skip characters

A very simple function that can be used such that it returns a pointer to the first character on which func returned 0. However, ...
3
votes
1answer
61 views

UNIX calendar(1) in C

This is a simple implementation of the calendar(1) utility included in some UNIX systems (all BSDs have it, GNU has not). I do not have much experience with ...
2
votes
2answers
1k views

How to do modulo thing fast (less execution time)

I was solving a question on a coding website and this website has a limit for execution time of code. My code takes 1.01 sec but the limit is 1 sec. I am unable to find any changes in my code that ...
2
votes
1answer
44 views

Linked list - append, insert, print

I am a beginner in C and am learning linked lists. I have made a program to implement a linked list, allowing certain operations on the linked list. There are 3 functions: ...
4
votes
2answers
90 views

Longest Palindromic Subsequence Multithread in C

I'm trying to learn how to multithread with c, and thought that the longest palindromic subsequence problem would be a good place to start. The idea is that we run two threads and compare their ...
3
votes
0answers
37 views

X11 file manager in C, using Xlib and imlib2

This is a still incomplete file manager for X11. It can only navigate through directories, select files (and do nothing with them), call a script to open files, and call a script to produce and cache ...
0
votes
0answers
33 views

Class file reader for simple java virtual machine

I implemented a simple Java virtual machine in C. Here it is: https://github.com/phillbush/jvm It includes two programs: javap(1), a Java disassembler; and java(1), the JVM itself. It does not have a ...
7
votes
2answers
209 views

Word wrap with file input & ouput

As this is a very basic word wrap program, it has at least the following 3 limitations :- The file should have a terminating newline. The column number at which the lines are to be wrapped must be ...
5
votes
2answers
233 views

Radix sort with benchmarks

I am trying to time radix sort on 128 bit unsigned integers for different base sizes (that I call bitwidth). My code has at least the following problems: The radix sort itself may run slower than it ...
5
votes
2answers
81 views

Reverse Polish Notation in C (using a Finite State Machine)

I recently learned about Finite State Machines (FSM) and thought I'd use that to implement a Reverse Polish Notation (RPN) calculator. I wanted it to also work nicely with the unix pipe. For example, ...
4
votes
1answer
67 views

Faster AAN algorithm for calculating Discrete Cosine Transform

I was implementing the AAN algorithm for computing the 2D Discrete Cosine Transform on an 8*8 array. I perform both the forward and inverse AAN algorithms. My code is extremely fast compared to the ...
7
votes
3answers
2k views

Fizzbuzz in C lang

This is the first time I have recoded in C for several years and I would like to know how clean my code is. ...
4
votes
1answer
279 views

4x4 double precision matrix multiply using AVX intrinsics (inc. benchmarks)

Benchmark An optimised 4x4 double precision matrix multiply using intel AVX intrinsics. Two different variations. Gist For quick benchmark (with a compatible system) copy paste the command below. Runs ...
3
votes
2answers
78 views

floor modulo or modulo rounding towards negative infinity

The first function will always try to correct the final result, while the second uses a conditional to know when to compensate. I think that in general the second function will be faster, but it will ...
2
votes
1answer
71 views

encrypt files using a variant of Vernam Cipher in C language

I'm coding this program that allows you to encrypt files using vernam cipher in C language. I would be glad if you could inspect my code and tell me if I can make some improvements to it or if there ...
3
votes
2answers
63 views

Simplify 2D point angle comparator

I have a comparison function for comparing two points in 2 (or more) dimensions based on the angle of each point in standard polar coordinates. In other words, a point ...
3
votes
1answer
86 views

Compiling and running a program to generate fractal images

I'm making images. My steps are: create PGM files using a C program convert/resize PGM to PNG using Image Magic remove (big) PGM files To do it I use Make and a Bash script. The Makefile is very ...
5
votes
6answers
1k views

Implementation of itoa which allocates the string

This is my implementation of itoa() (Integer to Alpha), which converts an integer to a string. Memory management and optimization is important. The caller is not ...
4
votes
2answers
170 views

CGI script that reads or writes its height and weight configuration

UPDATES: I'm looking for an answer that can answer the questions listed in the post. Moreover, this answer will not only continue my way of thinking, but also give feedback based on it. It's just like ...
2
votes
3answers
167 views

Finding n-th smallest Palindrome number (where 1<=n<=5000 and the palindrome number must have odd number of digits)

I am working on this code from 3 days from a website called Codechef, the code compiles, executes and even give correct results but my code is taking 1.01 sec, but the time limit for question is 1sec,...
1
vote
2answers
88 views

Find largest palindromic substrings in a string

I have written some code to find the largest palindromic sub-strings in a string without repeating any character. Example input abappabaxhhh output ...
5
votes
2answers
520 views

Replace n or all occurrences of substring in C

I wrote this code as an answer to a question. But I'd like you to have a look at it. This post is basically a copy of the answer I posted. The code does no error checking. It assumes that the output ...
1
vote
3answers
64 views

Recursive power (mathematical operation) function in C

How to make a C recursive exponentiation (power) function better? I developed a pretty simple (yet decent, imo) power function for the sake of learning. I'm not quite trying to compete with ...
1
vote
1answer
108 views

Target OS implementation

I was able to make an implementation to detect the OS. I'm not sure if it works the way it should, so I asked this question TargetOS.hpp ...
11
votes
3answers
1k views

My blit function for my own graphics library

Here is a blit function for a graphics library I made. I've built a small graphics library that uses an palette-indexed spritesheet to hold all of the game's sprites. The blit function copies parts of ...
-2
votes
1answer
72 views

Find repeating pattern in a string

I have written a C function that finds the shortest substring that can be repeated to produce the entire string. input: abcdeabcde result: ...

1
2 3 4 5
70