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
2 votes
1 answer
36 views

Advent of Code 2023 day 1: Trebuchet (Part 1 and 2)

Part 1: The task involves analyzing a calibration document containing lines of text. Each line represents a calibration value that needs to be recovered by extracting the first and last digits and ...
Harith's user avatar
  • 2,364
-2 votes
0 answers
28 views

Im new to Programming and my code doesnt work [closed]

This program should output the smallest array index of the most common letter in the string and it works for some inputs but for example "zzz" and "AAA" outputs 1 instead of 0 :( <...
 sora's user avatar
3 votes
1 answer
81 views

Simple hash table written in C with REPL

This is a simple hash table I've written in C. It is a closed-addressing hash table with TABLE_SIZE number of buckets. The hash ...
Amir reza Riahi's user avatar
1 vote
1 answer
80 views

Simple text file encryption and decryption

Short introduction; recently I've completed a basic course on C but other than that I have no programming experience and I am a total beginner. As a practice project and to practice reading from and ...
Reslashd's user avatar
13 votes
7 answers
2k views

Optimise a program that outputs the earliest date

I am attempting to solve Question 10 of Chapter 6 of the C programming: A modern approach book. The question asks to write a program that determines the earliest date from a sequence of user-inputted ...
Laika's user avatar
  • 131
4 votes
3 answers
552 views

char* to integer implementation (atoi with saturation to INT_MIN or INT_MAX on overflow)

I am learning C. As a task, I need to write a get_int function that will convert a char* to ...
aliheym's user avatar
  • 51
4 votes
2 answers
837 views

C Bit Utility Functions: Popcount, Trailing Zeros Count, Reverse All Bits

Here are some utility bitwise functions for 64 bit integers. I have independently derived inv64 (inverse all bits) and pcnt64 (...
user16217248's user avatar
0 votes
1 answer
71 views

C Element based FiFo-Buffer Implementation

Hey, i just finished work on a Element based FiFo Buffer in C. Layout of this question: Intro .h File .c File Usage Example Intended Use-cases Question .h File ...
ElectronicsStudent's user avatar
16 votes
7 answers
3k views

Image Processing Application in C

I'm making a image processing application in c from scratch using P6 ppm images, I want some input on my code before I start adding more features to prevent it from falling apart if it's not well ...
Ishaan Vatus's user avatar
0 votes
3 answers
68 views

another Merge Sort

I've tried to implement merge sort in c with varying degrees of success, one was correctly sorting the array but leaking memory, one was neither sorting the array and leaking memory. The following was ...
Voiceroy's user avatar
  • 103
7 votes
1 answer
685 views

Boolean conversion for fscanf()

In answering How to do file I/O with bool in C?, I made a helper function that used fgetc() calls to substitute the missing ...
chux - Reinstate Monica's user avatar
11 votes
4 answers
2k views

Simple Key Value Database using C

I was recently doing an assignment for a job interview, which asked to create a simple key value database with 4 command line operations: create key value: Adds a key value pair/updates an existing ...
P4PL4's user avatar
  • 111
1 vote
2 answers
1k views

Calling fgets() twice

I am a beginner. I have really struggled with fgets() when using the function twice. I am on Windows with VS Code and C++ extension. My test program is working, but it is IMHO lengthy and complicated ...
mortenlund's user avatar
3 votes
1 answer
136 views

Filter: BMP Image Filtering Tool - follow-up

This is a follow-up of this quesiton: Filter: BMP Image Filtering Tool Changes: Added comments where necessary. Added checks for integer overflow. Added support for input and output redirection. ...
Harith's user avatar
  • 2,364
1 vote
0 answers
63 views

binary semaphores implementation pthread

Can someone see if have not made some stupid mistakes in the binary semaphore implementation? I know that some more checks have to be added but I have eventually lost the initial idea in the details. <...
0___________'s user avatar
4 votes
1 answer
229 views

200 line Brainfuck Interpreter

I wrote a simple brainfuck interpreter in C99. Coming from a background of C++ made the task easier, but still there is some stuff I had to get used too. The program accepts a path to a brainfuck file ...
William Redding's user avatar
0 votes
2 answers
126 views

Array list implementation in C

Array-List-int.h ...
Kushagr Jaiswal's user avatar
5 votes
1 answer
383 views

Simple malloc and free implementation

I am trying to implement a simple malloc and free. The buffer is a char array. Each chunk's address is calculated using the size of the previous chunk. ...
user3280530's user avatar
1 vote
1 answer
77 views

Poker Hand Evaluation evaluation

Several days ago, a question on this topic was posted to SO. The problem turned out to be the OP's test cases did not reveal a deficiency in the code. This challenge caught my attention. Writing the ...
Fe2O3's user avatar
  • 183
1 vote
2 answers
63 views

bucketsort with multiprocessing

I want to compare the procedure time for each number of process. I made 5000000 numbers in input.txt in random order. I read it and do bucket sorting with ...
seokkyu's user avatar
  • 11
6 votes
4 answers
966 views

Filter: BMP Image Filtering Tool

Filter is a C program that allows you to apply filters to BMP images. Usage: Usage: filter [OPTIONS] <infile> <outfile> Review Goals: General coding ...
Harith's user avatar
  • 2,364
4 votes
2 answers
2k views

Linked list and array list performance comparison in C

After watching Stroustrup's presentation on performance comparison between vectors and linked lists (https://youtu.be/YQs6IC-vgmo?si=9r5wXqnwkmN29xqn), I've decided it would be a good problem to get a ...
low-altitude's user avatar
5 votes
2 answers
314 views

Wordle50 - A Command-Line Word Game

"Wordle50" is a command-line-based adaptation of the popular Wordle daily word game. In this word-guessing game, players aim to decipher a randomly selected word with lengths varying from 5 ...
Harith's user avatar
  • 2,364
17 votes
5 answers
5k views

malloc() and free() implementation

I'm looking for a code review of my custom memory allocation library (written for educational purposes), which includes malloc(), ...
Harith's user avatar
  • 2,364
5 votes
3 answers
769 views

Implementation of recursive `ls` utility

Recently I wrote my own implementation of a utility for recursive output of the directories' contents, kind of similar to the ls Linux utility with the ...
andylvua's user avatar
  • 215
3 votes
1 answer
94 views

HTTP Request-Line parser

I am trying to write an HTTP/1.0 (RFC 1945) parser in C, so I started with the Request-Line. Ideally, the parser should return one of the three: The request is valid. The request is malformed, but ...
Schilive's user avatar
  • 131
4 votes
1 answer
332 views

Porting xoroshiro1024** from C to C#, and seeding it

I require a PRNG which: Has repeatable results from a given state. Is both seeded from and has a state containing a sufficiently large amount of data (somewhere in the region of 700 bits or more) to ...
Pikanchion's user avatar
1 vote
2 answers
122 views

Ackermann function iterative-recursive form in C

I am trying to write the Ackermann function iterative in m and recursive in n. I got to this point where the code I provided below work for all values below Ack(5,0) but it overflows after this value. ...
anton's user avatar
  • 11
3 votes
1 answer
106 views

C-style double expression parser

The purpose of this code is to parse any expression as could appear in C that involves doubles or functions that involve only doubles. I have written parsers before: Command line calculator in C ...
user16217248's user avatar
5 votes
1 answer
86 views

Small HTTP client/SDK created using libcurl in C language

I created a SDK in C for my Rust project (a key value store in Rust). It should give access to the HTTP routes in a simple manner. (I never worked with C outside of university.) I used: ...
Auyer's user avatar
  • 153
6 votes
3 answers
631 views

Redefining queue with different front and rear

...
Sai_krishna's user avatar
1 vote
2 answers
90 views

Rate my Makefile

Here's the Makefile I've built up over the last two years which I use as a template (most often verbatim apart from target name(s)). It's meant to be used for C ...
ice-wind's user avatar
  • 133
1 vote
5 answers
246 views

Sum of bitwise XOR of each subarray weighted by length

here is the problem statement You are given an array a of length n consisting of non-negative integers. You have to calculate the value of \$\sum_{l=1}^n \sum_{r=l}^n f(l,r)\cdot (r - l + 1)\$ where \...
Gurnoor Singh's user avatar
2 votes
2 answers
142 views

Checking a mastermind answer as fast as possible

This is not your typical mastermind question, I am not trying to find the right answer. Merely to check the answer and provide a result as fast as possible. The function signature cannot be changed, ...
ice-wind's user avatar
  • 133
1 vote
2 answers
223 views

Iterating the octree while keeping track of the positive neighboring nodes

Review context can be found here: 32x32x32 Units Octree With 15-Bit Voxels: Second Edition The above question and the self answer include information such as the definition of the ...
user16217248's user avatar
4 votes
2 answers
104 views

implementation of Conway's game of life in C for ansi terminals

I've been learning C for some quite time now and wanted to test my skills by implementing the game of life in C. Please give me a general review, and include the style. Is code like that of function ...
Hansoko's user avatar
  • 143
3 votes
2 answers
221 views

32x32x32 Units Octree With 15-Bit Voxels: Second Edition

A while back I made an octree system that stores 15-bit voxel in a 32x32x32 voxel octree: 32x32x32 units octree, that supports 15-bit data units I have since improved upon this system. The new octree ...
user16217248's user avatar
5 votes
2 answers
512 views

Stopwatch program written in C, using Pico W

I've a raspberry Pico W and developed a simple stopwatch program in C. I configured GPIO pin 15 as an input and enabled the internal pull-up resistor. If the state is high, I will start the timer and ...
Isakkiii's user avatar
9 votes
2 answers
119 views

Hangman game in C

I am a beginner who wrote this simple Hangman game in C for fun and to practice programming. I am looking for advice on optimizing this code and making it adhere to best practices. Are there too many ...
smwt's user avatar
  • 103
2 votes
4 answers
248 views

Generic type data storage

We have a module which can be used by user to store and load value of variables. Every variable has an index associated with it (in the shown code cample this is ommitted and index is instead the data ...
user1806687's user avatar
0 votes
2 answers
102 views

Improving performance of mandelbrot set calculation

I am making a hobby OS, and I thought about adding a command for interactively rendering the Mandelbrot set. The "interactive" part is not really important, but I wanted to check if the ...
trxgnyp1's user avatar
  • 111
0 votes
0 answers
45 views

Finding the pivot point in a rotated array which has been shifted from kth element

I'm trying to solve the following problem: Joker has a deck of n cards, each with a value written on it. The cards are arranged in ascending order from top to bottom. Joker's master performs a hidden ...
driver's user avatar
  • 212
0 votes
0 answers
42 views

C idiom for multi-layer buffered input with processing

I'm writing a bit-level IO code that handles endianness conversion for the short/uint16_t type in the IO subroutines. Here's the code: ...
DannyNiu's user avatar
  • 310
5 votes
3 answers
103 views

Download stock data from YFinance

As a project to get more familiar with curl, I decided to write a program that downloads stock data from Yahoo Finance, and does arbitrary analysis on that data. I would like to receive any critiques ...
Linny's user avatar
  • 9,989
2 votes
1 answer
61 views

K&R excercise 1-21 Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing

Exercise 1-21. Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing. Use the same tab stops as for detab. When either a tab or a ...
Hansoko's user avatar
  • 143
2 votes
1 answer
75 views

K&R "The C Programming Language" exercise 1-13: histograms

Exercise 1-13. Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical orientation is more challenging. The ...
Hansoko's user avatar
  • 143
4 votes
1 answer
225 views

K&R exercise 3-1

...
Hansoko's user avatar
  • 143
3 votes
1 answer
78 views

Arm GPIO driver

I'm new to bare-metal programming. I'm currently developing some drivers for my first project. This is a simple GPIO driver. I tested it and it's working fine. What do you guys think of it, and how ...
Double-Amphibian's user avatar
9 votes
3 answers
1k views

C function to read only numeric values

I'm learning C and as exercise I'm trying to implement a custom function to parse a input from user and return successfully only if the input is a number. These are my files, how could I improve it? ...
shark_sh's user avatar
1 vote
1 answer
74 views

CS50 Week 2: Converting vowels to numbers and outputting new string

Problem: User inputs a word or phrase as command-line argument and a new word is printed with some vowels replaced by numbers. Question: How do I improve my code design and style? Is it possible to ...
LearningALidl's user avatar

1
2 3 4 5
79