Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
0answers
22 views

Simple Socket Server in C for Windows

I have taken the code from a tutorial of Microsoft webpage. Of course, the example is for illustration only but I wanted to organize it and make it clear in order to understand it a little more. Here ...
12
votes
6answers
2k views

Tic-Tac-Toe for the terminal

I recently started learning C, and this is my first fairly large (to me) program. It's a basic Tic Tac Toe game for the console. There's no AI, it's just a 2-player game. Is there anything I can ...
7
votes
0answers
55 views

ASCII Mandelbrot Set “image” producer

As an exercise, I decided to try implementing a Mandelbrot Set viewer that produces ASCII images. Small Example: ...
2
votes
1answer
30 views

Stern's diatomic series fusc: replacing #define functions with two return values

I have a function to review which implements Stern's diatomic series fusc for a single word (ulong = unsigned long) in place, as ...
4
votes
1answer
52 views

Preperiodic, periodic or aperiodic binary string

This is extension of the rep-string task from Rosette code. I do not only want to check if the input string is the shortest periodic string (rep-string) or not, but also check if it is preperiodic. ...
134
votes
17answers
16k views

Disproving Euler proposition by brute force in C

I wrote a little bit of code to brute force disprove the Euler proposition that states: $$a^4 + b^4 + c^4 = d^4$$ has no solution when \$a\$, \$b\$, \$c\$, \$d\$ are positive integers. I'm no ...
-2
votes
1answer
50 views

Optimizing a method that generates more than 1000 objects of the same type

This simple piece of software is generating a vehicle object by using the get_vehicle() function, Whenever i need to generate a specific vehicle I pass in the vehicle ID to this method and it ...
11
votes
3answers
2k views

Calculate min, max, mean and median out of array

Another C exercise: Write a function that takes an array of 'ints' as its input and finds the smallest and largest elements. It should also compute the median and mean. Use a ...
7
votes
2answers
113 views

Register “%b” conversion specifier

I'm writing a library to register the b, B conversion specifiers and make them work the closest possible to ...
1
vote
0answers
45 views

Linked list delete a node with a particular value [closed]

I am trying to search a single linked list with a particular value and delete it. Only the first occurrence of the value. ...
26
votes
4answers
4k views

FIFO data structure in pure C

I programmed a generic queue in pure C and I'd love to receive some feedback from other programmers. You may use the following questions to guide your review. Is the API well thought and idiomatic? ...
3
votes
1answer
58 views

Sums of columns and diagonals of a matrix

I made a simple matrix program that prints some data..I want to know how to reduce amount of lines with some functions or whatever, because there is so much if-s,and for loops. Tried to make ...
4
votes
4answers
2k views

Primitive console string calculator in C

Recenlty I have finished this primitive console string calculator in C. I need your balanced criticism, I'd like to know what I have to correct, remake and learn. Permitted operations: ...
2
votes
1answer
43 views

Computing the cost for creating a perfect square (with N = 3)

You are given a square matrix \$A \in \mathbb{ N}^{n,n}\$, this number contains integers from \$1\$ to \$n^2\$. The task is to compute the minimal cost, to change this square into a perfect square. A ...
2
votes
1answer
46 views

Computing the difference of the cross-totals of the diagonals of a matrix

I have solved a seemingly easy problem: Given a square matrix, calculate the absolute difference between the sums of its diagonals. For example, the square matrix is shown below: $$\begin{bmatrix}...
3
votes
1answer
54 views

Lazy, Functional Parser Combinators

Parser Combinators are the amazingly elegant way to write parsers that has evolved over on the functional programming side of the world, but have been less available or accessible for imperative ...
1
vote
2answers
169 views

Multi-Threaded Cellular Automata Lab

I am trying to improve the performance of my cellular automata lab. I have two arrays of Doubles representing the current values and the next values. If I run the ...
2
votes
2answers
61 views

Split calculation string into parts

Our professor has given us the following task (its part of a bigger document full of tasks): Write a function in C that handles strings like "233+343" and parse them into the variables "iNum1", "cOp" ...
5
votes
2answers
125 views

First C program: records keyboard/mouse and simulates the recording afterwards

This is my first program ever made in C. Before that I programmed just a little bit in C++ (didn't touch OOP so I did only structural programming). This is my second "project" ever made, the first "...
1
vote
0answers
20 views

Does this implementation of mutex locks result in undefined behavior? [migrated]

I need to control the frequency at which main processes data. In the example, it just increases the value of a variable. I cannot use ...
19
votes
2answers
1k views

Yet another shell in C

I wrote this shell in C about a semester ago for a university assignment on operating systems. Even though I got a score of 10/10 in this assignment, I doubt it deserved it - The pipeline ...
1
vote
1answer
36 views

INI File configuration handler

I am currently working on a game, and I get the configuration in an .ini file, and I get information with this library https://github.com/benhoyt/inih I would like to improve the readability / ...
7
votes
2answers
4k views

Lightweight logging library in C

I want to get some practice in writing C libraries and so started with something I can use straight away, a logging library. It is very basic and only has two levels: log everything and log only ...
4
votes
4answers
173 views

Reading a text file that may have embedded nulls

I've always used fgets to read a file. However, I want to read a file that may have embedded \0. I thought of using ...
1
vote
0answers
13 views

Advent of Code 2018 Day 1 Part 2 [closed]

This is the problem: You notice that the device repeats the same frequency change list over and over. To calibrate the device, you need to find the first frequency it reaches twice. For ...
2
votes
2answers
295 views

Converting prefix expressions to infix

Here is my new working code. Man, working with strings in C is tedious and annoying. I had built the algorithm in short time, took hours figuring how to implement it properly in C. Tell me if there ...
11
votes
3answers
900 views

Total income program

I have my program working. I just need to redo it a little bit, and it could use some improvements. I got different % rates depending on what the income and status is. ...
-3
votes
2answers
67 views

Converting Array of `Float32` (`float`) to Array of `UINT8` (`unsigned char`) Using AVX2 [closed]

Given input array of Float32 (float) with numElements how could one efficiently convert it ...
2
votes
1answer
55 views

256-bit ASCII Color Encoded Hex Dump in C

I made this hex dump after being dissatisfied with the free hexdumps out there. The biggest dissatisfaction is that the encodings for the char bytes were not color encoded, just like the hexyl hexdump ...
0
votes
1answer
53 views

Converting Array of `UINT8` (`unsigned char`) to Array of `Float32` (`float`) Using AVX2

Given input array of UINT8 (unsigned char) with numElements how could one efficiently ...
6
votes
2answers
112 views

Finding median from unsorted array with duplicate elements without sorting it

I am implementing a method to find the median of an unsorted array using a counting sort. I would happily go for a median of medians or selection algorithm for better performance but they are ...
1
vote
1answer
60 views

Find the sum of the digits of a given number

I need to find the sum of the digits of the given number and repeat the process until the value lies between 1 to 9. e.g if the input is 72457 then, 7+2+4+5+7 = 25 2+5 = 7 so , the function ...
3
votes
2answers
82 views

Header file that includes all standard C library headers

The Standard C Library consists of various headers files. Often only a few select ones are needed for given code. Other times it is simply convenient coding to include them all in a .c file, even if ...
1
vote
3answers
82 views

Count unique digits in a given number

How do I find the number of unique digits in a given number. e.g if 'input1' is 252 it must return 1, since 5 is the non-repeating digit; if 'input1' is 25000 it must return 2, since digits 2 and 5 ...
5
votes
1answer
67 views

Two cross-platform implementations of getline in C

I created my cross-platform implementations of getline function in C. It takes different arguments and have different return values than 'original' ...
5
votes
2answers
81 views

Hash table with dynamic sized array in C

To gain a broader insight in things many (high-level language) programmers nowadays take for granted, I decided to study some of the more basic ways of storing data in memory. I wrote a program which ...
0
votes
1answer
33 views

Beginning C character array explanation [closed]

I have been following along the book 'The C Programming Language' 2nd edition by Kernighan and Ritchie. The below code is an exercise from the book. What I am confused about in this code is the ...
1
vote
1answer
46 views

strReadLine function (read line by line from a string)

I'm new to C language and want to read a string line by line, I made this function and want to know what do you think about it, can I rely on it a production environment ? ...
1
vote
0answers
37 views

Prompting the user to input a data value into an element in a linked list

I'm working through a practice problem that is having me build and modify a linked list over a series of steps. I am particularly interested in knowing if there's a more elegant way of prompting the ...
2
votes
1answer
81 views

Beginning C, hangman

I have been working on this hangman game for a little while trying to get familiar with C programming. The game seems to work fine but I am looking for some pointers on my code. Are the global ...
3
votes
1answer
44 views

Calling a Function to Calculate Multiple Coefficients

I'm working through a practice problem and am wondering if there's a more efficient way of writing my code and/or if the syntax for my pointers looks correct. The practice problem: Given the ...
3
votes
2answers
4k views

Phonebook implementation in C

I have implemented a phonebook in C using a singly linked list sorted data structure. This is my first average-major project. I need some reviews so that I can improve my coding standards. The ...
7
votes
3answers
1k views

malloc in main() or malloc in another function: allocating memory for a struct and its members

When initializing a struct in C, we can allocate memory inside the main function or within another function and return a pointer to the newly created struct. This ...
1
vote
1answer
72 views

Slow insertion into a Red Black tree

I am trying to implement a red black tree. The problem is that the code runs slowly and I wonder if I did something wrong or just did it too many times. I already checked and the problem is in the ...
5
votes
1answer
69 views

Error handling function (Win32/C)

I have written the following function to be a general "error logging" solution for my Windows API projects. Basically, given a Windows system error code (a la ...
1
vote
1answer
42 views

Understand the dependency levels of makefiles

Assume that the project has the following files, where the first files is dependent on the files under it's category in the unordered list: main.c global.h (contains enumerations and #define ...
3
votes
0answers
54 views

Generic Makefile for C projects

I'm trying to create a generic Makefile that will work with the following directory structure: Project Directory Makefile main.c source file source directory Source files include directory Header ...
12
votes
4answers
7k views

Calculating longest increasing sub-sequence recursively

I have trouble understanding recursion, so I'm trying to implement algorithms using it. I wrote this code that calculates the length of the longest increasing sub-sequence. How can I improve this? <...
1
vote
1answer
41 views

Bubble sort in C (for strings)

What do you think of this bubble sorting function in C, for a string array? I would like to improve the readability, performance, and any good practices. ...
3
votes
1answer
113 views

Program that finds prime numbers in a specific range

I'm kinda new to programming, and as a solution to an exercise, I made a program to find prime numbers in a range. It runs just right for small ranges of numbers, but for this exercise we are given a ...