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
1answer
43 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 ...
1
vote
0answers
43 views

Linked list delete a node with a particular value [on hold]

I am trying to search a single linked list with a particular value and delete it. Only the first occurrence of the value. ...
3
votes
1answer
54 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 ...
-2
votes
0answers
19 views

computing sum from buffer in C pthread producer consumer [closed]

I want to calculate the sum of the elements in a buffer, basicly one thread compute a parcial sum, and the other thread reads the buffer and sum the elements. Also, is possible to terminate the ...
2
votes
1answer
42 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 ...
-3
votes
0answers
28 views

writing a code in c language that checks a certain alphabetical order input ,using only loops and condition statement [closed]

I was asked to write a code in c language that checks a certain alphabetical order from the input and determines how many "legal" orders are there. the order goes like this: I receive multiple inputs ...
4
votes
1answer
46 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. ...
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
52 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 ...
2
votes
1answer
45 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}...
1
vote
2answers
168 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 ...
7
votes
2answers
111 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 ...
2
votes
2answers
60 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" ...
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 ...
5
votes
2answers
124 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
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 ...
4
votes
4answers
165 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
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 / ...
-3
votes
2answers
65 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 ...
0
votes
1answer
52 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 ...
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 ...
6
votes
2answers
109 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 ...
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
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 ...
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 ...
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 ...
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
41 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 ...
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 ...
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. ...
6
votes
0answers
46 views

ASCII Mandelbrot Set “image” producer

As an exercise, I decided to try implementing a Mandelbrot Set viewer that produces ASCII images. Small Example: ...
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 ...
4
votes
1answer
48 views

Bar graph of Easter date distribution

Computing Easter for a given year is a classic computational problem. It is also one of the few cases when code seems to just have to live with magic numbers. Alternative to magic numbers: Decoding ...
5
votes
2answers
233 views

Calculating the number of coins in money change

I wrote a program that calculates the minimum number of coins required to give a user change. One concern I have is: When do we initialize the value of a float to be negative or positive? I recently ...
6
votes
2answers
181 views

Program that generates brainfuck code that outputs given text

I created program that generates brainfuck code that outputs given text. Arguments for the program are input file with the text and ...
3
votes
1answer
67 views

Generic Macro Generated Hashset in C

The Hashset uses open addressing, linear probing and Robin Hood hashing for handling collisions. It comes with insert and remove ...
6
votes
1answer
74 views

Per pixel Image Computation with Gamma Correction in OpenGL and C [closed]

I've been working on a way to optimize pixel computation in OpenGL with C. If this information helps, my current environtment = Linux (terminal) + GPU (Nvidia 1080Ti). I'm working with old OpenGL (...
0
votes
3answers
135 views

To find if a character is a delimiter

I have a function to check if a character is a delimiter and I wonder if it is consistent or can be improved: ...
8
votes
1answer
145 views

myUTF-8 small lib (validate UTF-8, guess language, count chars)

I'm new to C language and never got my self into the details of UTF-8, and after reading some articles about it, I wanted to try and play with UTF-8 with C language for both fun and practicing ...
4
votes
2answers
51 views

String joining function in C

I wrote a function that joins a collection of Strings with a delimiter. It's based on Java's version of the function. I'm assuming C has some similar built-in. Example: ...
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' ...
4
votes
2answers
47 views

CS50 Vigenere program

I wrote a program for a problem in Harvard's CS50 course, Vigenere (week 2). Here is a description of what the program needs to do: Design and implement a program that encrypts messages using ...
6
votes
1answer
129 views

Single-Linked List in C - beginner

I'm a python dev by day trying to learn C. This is a simple implementation of a singly linked list. As a noob I would like comments on style and C conventions as well as functional remarks on memory ...
3
votes
4answers
99 views

Linux wc command in C

I'm working on my implementaion of the linux wc command. I finally have something that is working properly (with no options yet) but i think it needs a lot of "cleaning". I mean, i highly disrespect ...
4
votes
1answer
39 views

Beginner Console Conway's Game of Life in C

For an Information System Security course I'll be taking later this year, I need to learn C and decided to start learning it yesterday. Conway's Game of Life has historically been a good project to ...
6
votes
1answer
58 views

Linux cat command in C

I wrote my own implementation of the linux cat command in C for my computer laboratory class. We were asked to replicate its functionality with no options passed as arguments or with just the -b, -n ...
4
votes
2answers
57 views

Android NDK Low performance

I am trying to write a NDK program for quicksorting an array. However, in my benchmarks C is doing consistently worse than Java, as indicated by my results: Java 1190625 C 1809218 Java 895104 C ...
8
votes
4answers
364 views

strToHex ( string to its hex representation as string)

I want to convert strings to their hex representations as strings too (like hex dump programs), for example "abz" to "61627A". ...
10
votes
1answer
142 views

Jack compiler in C

I have been doing projects from the book The Elements of Computing Systems. Under the scope of project 10 and project 11, I had to implement a compiler for a (toy) programming language called Jack (...