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.

-1
votes
0answers
25 views

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

Given input array of Float32 (float) with numElements how could one efficiently convert it ...
1
vote
1answer
42 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 ...
1
vote
0answers
22 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
91 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
29 views

Beginning C character array explanation [on hold]

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
35 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
43 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
68 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 ...
6
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 ...
0
votes
0answers
21 views

Prints information about a restaurant (provided by user input) using a .txt file [on hold]

My code works, but not the way I want it to. If a user provides a string, even if the string doesn't match a name in the array, it will print information about all 5 restaurants. If I put a break ...
1
vote
1answer
39 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
67 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
38 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. ...
-1
votes
0answers
61 views

Formatting integers with commas (12345 → 12,345)

Beginner/occasional C tinkerer here. (Reasonably comfortable with scripting languages, tend to avoid C due to its terseness, but trying to work past that.) I happened to want to insert commas into ...
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
67 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
229 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
174 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
65 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
73 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
132 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
143 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
49 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
64 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
36 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
125 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
95 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
38 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
56 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
54 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
356 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
120 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 (...
5
votes
0answers
51 views

Engineering an even faster qsort

I understand that C++ STL template sort runs faster than qsort in C because ...
4
votes
2answers
117 views

strTok function (thread safe, supports empty tokens, doesn't change string)

I'm new to C language and want to explode a string like we do in PHP explode() function, I searched for a built-in function with the C standard library, and I found ...
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 ? ...
0
votes
0answers
32 views

Creating a Word Search Program in C

I am currently creating a word search program using C. I have created 5 different arrays for subjects containing 15 different words from each. I must also create a program that creates a 2D grid of ...
1
vote
0answers
23 views

Sort an array of strings using bubble sort

I have this following code to sort an array of strings order by ASCII value (alphabetically) using bubble sort. ...
2
votes
1answer
42 views

Generic Macro Generated Linked List in C

Generate a linked list of any type using macros. The linked list contains functions for adding and removing elements to both ends and also at the middle. You can also add elements relatively to a list ...
1
vote
1answer
38 views

Multiple Choice Four-Function Math Game

I created a very simple multiple choice math practice game in C for a fun project. Essentially the user first enters how many questions they want, then they enter what operation (+, -, *, /) they want ...
3
votes
2answers
66 views

Number guessing game in C

This is just a little number guessing game. I know it's simple but I am a newbie in C and I think such a little example can be enough for finding simple design flaws that can than be eliminated. If ...
2
votes
1answer
42 views

Constructor for a packagetarget struct

As many of you know goto is usually signs of code smell. However I thought this could be an appropriate case, and would like confirmation or criticism. Unnecessary ...
1
vote
1answer
30 views

Read message protocol socket c

My code recovers all sent messages (ending with "\r\n") in function read_message. I would like to improve this code, make it more efficient? If it's possible, I am ...
2
votes
1answer
62 views

Removing node from a linked list

I'm implementing the singly linked list data structure and functions to work with it. In particular I'm concerned about prepending and removing nodes. Currently I defined linked list as follows: <...
8
votes
2answers
148 views

Brainfuck interpreter in C 3

I created my brainfuck interpreter and I would like to know what can be done better and is the code clear and readable. I will be very thankful for opinions and suggestions. Here is the code: ...
4
votes
1answer
38 views

unordered_set: a hash table -based set data structure in C89

In this post, I present a hash table -based set data structure written in C89: unordered_set.h ...
2
votes
1answer
26 views

Uni- and bidirectional pseudo-generic shortest path finders in C89

I have implemented two related shortest path algorithms for unweighted graphs in C89. My attempt was to learn some more idiomatic C constructs such as genericity (a client programmer should be able to ...
1
vote
1answer
56 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 ...
17
votes
2answers
2k views

Simple recursive Sudoku solver

My Sudoku solver is fast enough and good with small data (4*4 and 9*9 Sudoku). But with a 16*16 board it takes too long and doesn't solve 25*25 Sudoku at all. How can I improve my program in order to ...