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
1
vote
0answers
12 views

Unique and shared resource owner

I need a unique_ptr and shared_ptr like structure, but instead of pointers, I would like to store some kind of reference to a resource. It is usually just an int ...
2
votes
1answer
14 views

Basic Subnet Mask Calculator + A Little Extra

For my Networking class, we learned about subnetting and subnet masks. I decided to write a little "calculator" (a generous term) that when given n-many network ...
2
votes
0answers
23 views

C program that dynamically allocates and fills 2 matrices, verifies if the smaller one is a subset of the other, and checks a condition

Yesterday, I asked this question because I was asked to implement a software that used variably sized matrices with C89's limitation, so I had to practise dynamic pointer-to-pointer allocation. After ...
4
votes
2answers
42 views

converting bits binary to bcd

I wrote a code that requests user input and then converts binary to bcd then back to binary using bitwise operations. While I think my code is good I want to know if there is a better way to write the ...
4
votes
1answer
69 views

Recipe Manager in C

I have finished a school project recently which was a recipe manager to be implemented in C. Coming from C# I am really struggling on getting used to the programming style of C. I feel like the code ...
6
votes
2answers
416 views

C - manually parsing char* into integer

I'm trying to parse a char* into an int without using atoi(). I walk through the string, ...
-2
votes
0answers
25 views

Adding or deleting elements from a linked list [closed]

I'm relatively new to programming as I've just started university. My assignment is to develop a program (by using a function and a linked list with pointers with integer elements) which does the ...
3
votes
1answer
54 views

Finite State Machine / Scene Manager in C

I'm new to C programming but this is my attempt at a Scene/State machine. I haven't had a code review before so I'm guessing this is gonna hurt :D § Preliminary SceneFSM manages Scenes, one Scene "...
4
votes
3answers
458 views

Terminal-based Blackjack

Normally I code in Java but have recently been trying to teach myself C for a university course I will be taking next semester. (I'm about to enter my third year). I wouldn't consider myself the best ...
10
votes
3answers
2k views

C program for 'Reverse DNS lookup'

I have written the following code for doing a reverse dns lookup. I'm not sure if there are any errors in it. Please have a look: ...
1
vote
2answers
956 views

Bubble Sort and Selection Sort (C)

I used the "long" form of all math statements, avoided the use of pointers, and used only while loops for aesthetic purposes (simply put, I think the code is prettier when it is written like that.) I ...
1
vote
2answers
46 views

Reversing input characters

The given code reverses an array of input characters. The additional while loop in reverse() function is unnecessary I guess. ...
4
votes
1answer
64 views

Spawn a Linux subprocess without leaking FDs

I'm working on a library of shell utilities for Swift, and at the core of it is the need to spawn a subprocess. For Linux, I came up with the following function to do the low-level work. ...
11
votes
8answers
3k views

Program that converts a number to a letter of the alphabet - follow-up

This is a follow up from my previous post: Program that converts a number to a letter of the alphabet This is meant to teach my little brother (who only knows how to make games in Geometry Dash) ...
-2
votes
0answers
18 views

Atmega2560/328P One Wire Driver [closed]

I recently found myself not overly impressed with the arduino onewire library since it relies on delay() (which is blocking) for just about all timing (even those long reset pulses with 480us, which ...
8
votes
2answers
126 views

Printing a 2-D array diagonally

The case scenario: A 2-D array is given: 1 3 6 10 15 2 5 9 14 19 4 8 13 18 22 7 12 17 21 24 11 16 20 23 25 and its size ...
5
votes
2answers
1k views

Generic dynamic array implementation in C

I'm working on my own generic-type dynamic array in C99 and I would like to hear your input, suggestions, ideas, anything! What I most care about is: 1) correctness and 2) performance. So far, I've ...
4
votes
1answer
68 views

C functions for fast IO for competitive programming

In some (perhaps not well-designed) competitive programming problems, the runtime and score is dependent on how fast your program can process input. Therefore I've written a small C99 library with ...
1
vote
1answer
45 views

Implement function in doubly linked list

The following is the entire function for implementing a doubly linked list. Can anyone show me if there is a better way to write these functions, especially the ...
4
votes
3answers
102 views

Rotate square matrix clockwise by 90degrees

...
0
votes
3answers
91 views

Safer & simpler allocation functions and macros

I wrote a bunch of functions and macros for safer and simpler allocation. They are documented in their files. Disclaimer: The library requires POSIX extensions, GCC extensions, and LIBBSD ...
6
votes
3answers
180 views

Chess game in C

I've never programmed in C before, but decided I wanted to try making Chess. Currently there's no way to check whether the game has ended. Was looking for critique for future projects. ...
2
votes
1answer
80 views

Permutation 1…N. Answer queries “How many numbers between [X,Y] position are in the interval [L,K]”?

So I am solving this task: We have an permutation of the numbers 1..n. I need to answer m queries: -How many numbers between X-th and Y-th position are in the interval [L,K] (<=k and >= L)? So my ...
3
votes
1answer
38 views

Linked list where user replace a chosen number in the list with a number chosen by user - how can it be improved?

I'm quite new to C programming so I'm trying to learn the basics. I've made a program that creates a linked list of numbers, then ask user for which number he/she wants to replace and then what number ...
2
votes
2answers
43 views

Flexible array member polyfill && Vector implementation in C89

I wanted a polyfill of flexible array members in C89. So I made something similar, and made a toy std::vector with limited functionality on top of it. Here is the code: vector.h ...
4
votes
1answer
57 views

Is this a good way to write a lexer?

I don't know whether if this is the right place to ask this. I am semi-beginner in C. I always wanted to build my own Programming Language. Here I have built a lexical analyser completely myself. ...
1
vote
1answer
57 views

Convert image to grayscale

To convert JPEG file, C function, bgraToGrayscale is called from Swift. Is there a better way to 1.allocate memory and 2.access pointers than the ways they have been done in code below? And ...
5
votes
3answers
332 views

Ask the user a number between 2 and 20

Here is my attempt: ...
4
votes
2answers
76 views

Generic circular doubly-linked list v2

I've improved, with help of the answers and comments, the linked list that I posted yesterday. It's been through a lot of changes, and is much more useful and safe now. I documented the linked list ...
6
votes
5answers
116 views

Implemented command-line based merge-sort algorithm. How can I make the code efficient, robust, maintainable, secure?

This is follow up question regarding merge-sort implementation to the previous post. Recently I have implemented a command-line argument based merge-sort sorting algorithm. Format for command-line-...
6
votes
4answers
589 views

Generic circular doubly linked list

Edit: New version improved with the answers and comments received here: Generic circular doubly-linked list v2 I have written a linked list library that I can use whenever I need a linked list, so ...
2
votes
3answers
161 views

Adding two n and m bit binary numbers

Recently I was studying bitwise operators and bit-manipulation algorithms and I found out an algorithm to add two binary numbers. Pseudocode is as follows: ...
-1
votes
1answer
55 views

Interlock of some equipments in electrical power system using simple Arduino Uno code [closed]

I'm trying to implement some logic functions essential to control a small power system consisting of 2 Transformers labeled T1 and T2, 2 Generators (G1 and G2) and a bus tie (BT). I'm not going to ...
4
votes
2answers
110 views

Generic linked list in C

I have been trying to come up a generic C linked list to store data as it comes and later sort them to use it for various purpose. Please have a look at the code below an provide me your review ...
11
votes
5answers
921 views

Toy Vector Library - Magnitude & Unit Vector Functions

I'm writing a toy vector library in C to learn a bit about the language. The excerpt below shows my vector structure and two functions: vec2_magnitude calculates ...
3
votes
4answers
146 views

ASCII-art pyramid

I am studying C while listening to a lecture by myself. When I was studying coding and listening to a lecture, I heard that writing code should be concise and maintainable. But I didn't know if I was ...
23
votes
8answers
5k views

Random password generator in C

This is a simple password generator. What do you think about it? I am learning C for a while at school and at home. This just has a mix of symbols, lowercase, uppercase and numbers, with a ...
3
votes
0answers
38 views

Transfer an array of unknown size from C to Python using Ctypes

I am new to Ctypes. I am writing a piece of code that brings an array of unknown size from C to Python using Ctypes. Unknown size here mean that Python initially doesn't know the size of the array. C ...
2
votes
1answer
56 views

Thread Pool in C for web server

Please review the following code for thread pool in C (I wrote it to implement a threaded web server for my personal project). I have been programming in C++ and Java but never did any serious ...
4
votes
2answers
604 views

Print input lines longer than 80 characters in C

Exercise 1-17 from the book The C Programming Language: 2nd Edition, K&R Full description: Write a program to print all input lines that are longer than 80 characters. ...
4
votes
1answer
47 views

static memory block allocator in c99

I wrote this snippet to allocate blocks of memory, whose sizes and number are available during initialisation. I choose to equally divide the statically allocated memory. There are some error checks ...
3
votes
1answer
112 views

Simulate Tic Tac Toe game using C language

I made a Tic Tac Toe game using C. Here two players, player1 and player2, can participate and play. Please rate my code and suggest improvements. ...
2
votes
3answers
87 views

My own array implementation in C

I've been trying to remember old programming concepts like data structures. My first challenge was about implementing my own array of positive integers: ...
6
votes
3answers
115 views

Optimizing a raycaster

I have finished a raycaster, and I want to optimize it before I add other features, such as variable height walls, texture mapping and lighting. I'd like someone to review the code so I can improve it ...
8
votes
1answer
67 views

Direct Mapped Cache simulation

This is my attempt to build a simple simulation of a direct mapped cache, I'm new to C and trying to learn some low level concepts. I had some difficulties with the design, because I'm used to program ...
-5
votes
1answer
48 views

Find pair of adjacent prime numbers in a two-dimensional array

Does anybody know how to find pair of adjacent prime numbers in two-dimensional array, quicker than this? I'm talking especially about this part which looks for adjacent numbers not about function ...
4
votes
1answer
39 views

Open MPI: simple manager/workers pattern in C

I'm currently modifying a research project (massive test and benchmark of diverse conjectures to try and eventually solve the SSW conjecture) so that it can run on a big HPC architecture, which does ...
37
votes
4answers
10k views

Brainfuck interpreter written in C

I am a beginner with regards to C; I'm used to using high-level languages (Java, Python, JS, etc) and this is my first project in a lower-level language. I wrote a simple Brainfuck interpreter, given ...
0
votes
1answer
53 views

Optimizing code that needs to run through a lot of different numbers for Project Euler [closed]

I have been working on Project Euler problem number 12. I have code that will get me the right answer, however it takes too long. I know the code works because I have tested it multiple times with ...
3
votes
2answers
75 views

Link list working

I wrote this singly linked list and it worked fine,Now can anyone review my code. I want to do some more clean my delete and add function. And some abstraction. ...