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
3
votes
2answers
58 views

Type-independent vector in C

I wanted to create a vector that can be used for different types, as generics do not exist in C. I came up with an implementation that maintains a buffer on the heap and reallocs itself when the ...
3
votes
2answers
49 views

Semi-generic non-linked list using structs: Safety concerns

Based on my googling around generic lists in C I stumbled upon tagged unions. What I wanted to create was a data structure that can hold int, ...
1
vote
2answers
49 views

cs50 filter(more comfortable) - Image filters in C

I've been taking cs50 for about under a month now and I've finally finished with "filter" in pset4. The code passes all the green checks on check50. Our task was to implement functions in <...
0
votes
0answers
56 views

Finding the first null character in a file, if I am going to save everything before it in a malloc() block? [closed]

I need to know which is a better option, provided they both work as intended. I need to open a file, and load everything up to the first null character into a ...
11
votes
4answers
782 views

Conway's Game of Life in C

My programming background is mostly C++/C#. Lately i got interested in writing some C. So i implemented Conway's Game of Life using SDL2 for visualization. This is actually my first program written in ...
2
votes
2answers
56 views

Dynamic Array Based Stack in C

I wrote a dynamic stack in C that uses an array as a structure. I tried to maintain O(1) for push and pop and believe I have done so. I want to know what can be written in a cleaner way and if there ...
0
votes
0answers
21 views

Why am I unable to access File Permissions using scandir? [closed]

When I am in a different directory and try to use the following function on a certain folder/directory (i.e., when char *directory != the directory i am in), I end ...
-1
votes
0answers
54 views

How can shuffling be done without allocating an auxilliary array [closed]

Problem: Given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string. Return ...
3
votes
3answers
82 views

C Logging Function

I wrote this log function and it works but is there a better way to write into the file stream and console at the same time? ...
4
votes
2answers
250 views

FileParsing in C

So I have a text file filled with old onion links and its incredibly messy: ...
3
votes
2answers
60 views

Convert infix regular expression notation to postfix

This is a small part of a larger program for implementing a limited syntax regular expression constructor using Ken Thompson's construction algorithm. Converting to postfix before the regular ...
2
votes
2answers
69 views

Common Unit Testing Code – Follow Up

This question is a follow up question to the Common Unit Testing Code portion of my lexical analyzer questions. My primary concern is the code in the header file and the C source file that implements ...
1
vote
2answers
98 views

a simple implementation of unix2dos for windows

On linux there is the utility called unix2dos which converts UNIX EOLs(\n) to DOS EOLs(\r\n). However on windows there is no such tool so as a result I decided to make one. ...
1
vote
0answers
24 views

Code improvisation for below query [closed]

The below code is functional using an Arduino Uno board and DS1307/24LC08 Device. I have 6 keys in total: Relay selection - relay can be selected from 1-8 Combination selection. User can set relat 1 ...
1
vote
0answers
22 views

Improving sqlite3 code in swift using c api

Trying to come up with a pattern where the code to open db, writing queries is elegant and clean while handling all possible error conditions. Following code ...
9
votes
2answers
1k views

Can I draw a square with pixels more efficiently?

I'm drawing a square on a window using an implementation of Xlib. I put a colored pixel with my_pixel_put at a specific (...
5
votes
1answer
68 views

Hand Coded State Driven Lexical Analyzer in C With Unit Test Part C

This review is presented in 3 questions due to the amount of code: Part A contains the Lexical Analyzer and the main portion of the unit test code. Part B contains the lower level unit tests called ...
4
votes
1answer
38 views

Hand Coded State Driven Lexical Analyzer in C With Unit Test Part B

This review is presented in 3 questions due to the amount of code: Part A contains the Lexical Analyzer and the main portion of the unit test code. Part B (this question) contains the lower level ...
8
votes
2answers
105 views

Hand Coded State Driven Lexical Analyzer in C With Unit Test Part A

This code review is presented in 3 questions due to the amount of code: Part A (this question) contains the Lexical Analyzer and the main portion of the unit test code. Part B contains the lower ...
5
votes
3answers
95 views

Doubly linked-list implementation

I come from a C++ background, and I recently got into C, and one of the first things I made was a double linked list since I though it would be good practice for me with pointers and memory allocation....
10
votes
4answers
745 views

Insertion sort vs Selection Sort benchmarking

Over on Stack Overflow, I read an answer asserting that Insertion Sort was inferior to Selection Sort for array data (as opposed to linked list data) on account of the larger amount of data movement ...
2
votes
1answer
37 views

A simple C WinAPI program for terminating processes via process image names - follow-up

(See the previous (i.e. first) version of this tool.) After taking into consideration all the advice by Martin R, I ended up with the following tool for terminating all the processes with given ...
4
votes
0answers
63 views

Reduce size of minesweeper program to fit in qr code

I saw a guy who fit snake in a qr code and I wanted to do the same thing but with minesweeper. The maximum amount of data a qr code can hold is 3kb. My c program, without any compiler magic, takes up ...
9
votes
2answers
1k views

C Implementation of atof

I'm a beginner at C. I'm currently implementing atof to build a raytracer, however I'm still learning how to efficiently write programs. Assignement Instructions The program takes a scene description ...
5
votes
1answer
65 views

A simple C WinAPI program for terminating processes via process image names

(Also, see the next iteration.) I have this small program for terminating processes via their respective process image names (.exe files): ...
3
votes
1answer
129 views

Simple Windows implementation of the cat command

On Linux there is the cat command which outputs files concatenated but on Windows there exists no such command. As a result I decided to attempt to recreate a ...
6
votes
2answers
645 views

TicTacToe with AI in C

I recently started learning C, though I have some experience in other languages. I recently wrote a TicTacToe AI using the Minimax Algorithm in C. I would like to know how I could write better C. <...
5
votes
1answer
47 views

A* and ALT pathfinding in C tips

I adding some pathfinding to a game I'm working on. It primarily used A* with as suggested in the pathfinding articles at reb blob games. It works, but isn't very fast. It is a square grid map that (...
10
votes
2answers
109 views

Text based rendering/animation engine for the terminal

This project was highly inspired by the popular drawille project, that lets one draw to the terminal using the braille unicode characters. The advantage of drawing with braille characters compared to ...
3
votes
1answer
90 views

8 puzzle solver in C

The code works fine for inputs that have a solution. The goal board is 1 2 3 4 5 6 7 8 I have tried to implement using the A* search algorithm. The code runs for 2 seconds or slightly more time which ...
3
votes
0answers
45 views

Linear probing 16 hashmap elements in parallel using SIMD instrinsics

For my hashmap implementation, I'm caching hashes for each map element in an array of length NBUCKETS, where each element corresponds to an element in the hashmap. ...
8
votes
2answers
112 views

Text Parsing in C on a microcontroller

Microcontroller receive data on uart and call parser_i2c function when user presses enter e.g. parser_i2c(I2C scan) I want to parse following input from user communicated through uart I2C scan I2C ...
4
votes
0answers
54 views

Basic snake game in C

I wanted to learn C and Win32 so I thought the best way to start would be to create a simple game to get familiar with the language, so I made Snake. The games works perfectly except for sometimes ...
7
votes
2answers
633 views

Yet another dynamic array design in C

I've seen few similar post about dynamic array in C released as macros, but I tried a new approach to make it looks more like a ...
8
votes
2answers
60 views

Line wrapping text utility using fixed-size arrays

As an exercise, I've made a text processing utility that wraps arbitrarily long lines of text, but only using fixed-size arrays and other basic C features. I have mostly programmed in Python, C++ and ...
3
votes
2answers
80 views

Random alphanumeric string generator function (C, Windows, bcrypt.h)

The function uses the Windows "Cryptography API: Next Generation" (bcrypt.h)'s BCryptGenRandom function to generate ...
3
votes
2answers
79 views

Implementing metropolis algorithm in C

This is my second C program (an improved version of the first one). I want to optimize this simulation. Algorithm The simulation algorithm is: The system can go from \$i\$ to \$i+1\$ with probability ...
4
votes
2answers
92 views

ArrayList implementation in C

This is my first big project. I missed ArrayList a lot in C and thought that it would a very good learning exercise if I implemented my own in C. I tried to take all the features from Java's ArrayList ...
4
votes
1answer
85 views

Monte carlo simulation in C

This is my first C program. I want to optimize this simulation. Algorithm The simulation algorithm is: The system can go from \$i\$ to \$i+1\$ with probability \$e^{-L\theta(\rho_i)}\$, where \$\...
4
votes
2answers
56 views

Format string processing similar to date or printf()

I wrote a function that is supposed to take a format string similar to what date accepts and replace all format specifiers with strings provided by a callback ...
1
vote
1answer
70 views

Is there a better way to avoid repeated 'Len == 1' when interpreting booleans from strings?

My solution to string interpretation is pretty fast. However, I worry about repeated if (Len == 1). That might make the function bigger in the executable. How can I ...
4
votes
2answers
43 views

Checking String with is_numeric in C

I am a newbie in stack exchange code review. I just wrote a C function where the function checks if the given string is numeric or not. What do you think about my way of doing this? And could this be ...
5
votes
1answer
43 views

C: Sieve of Eratosthenes and next twin prime

I am wondering if I can get some feedback for my implementation of "Sieve of Eratosthenes" and twin prime. I followed this pseudocode. Few notes: I added ...
4
votes
2answers
97 views

Complex Calculator in C

I am Relatively new to C, and did a calculator for my first year project. Could you guys, rate the calculator's efficiency and suggest some improvements? Link to the previous version of this ...
6
votes
3answers
502 views

A program with a function that converts a string of digits into an integer value

Here is a programming task: Write a program with a function that converts a string of digits into an integer value. Do not use the strtol() function or any other ...
3
votes
1answer
62 views

Computing candidate popularity provided a voter's list of all the candidates sorted by preference

I have the following code: ...
11
votes
3answers
2k views

Hangman Bot built with performance in mind

I'm working on a bot that can use a wordlist to play hangman optimally as fast as possible. With the current implementation, the simulateGame function, which plays ...
9
votes
3answers
91 views

Parse string into a struct

I'm writing a C application for the Networking course at the University. Basically it's a UDP server that can receive two commands: GET key SET key value That are ...
10
votes
3answers
270 views

Compression Library for C using Huffman Coding

This is an update to a question I posed nearly two years ago about my implementation of Huffman Coding which I had written in C. Since then I have had time to grow as a programmer and have managed to ...

1
2 3 4 5
63