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
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

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
46 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 ...
5
votes
0answers
41 views

ASCII Mandelbrot Set “image” producer

As an exercise, I decided to try implementing a Mandelbrot Set viewer that produces ASCII images. Small Example: ...
4
votes
1answer
46 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 ...
2
votes
0answers
23 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 ...
5
votes
2answers
226 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 ...
8
votes
1answer
138 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 ...
6
votes
1answer
71 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 (...
3
votes
1answer
63 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 ...
3
votes
2answers
1k views

Prime number generator in C

I have to print numbers between two limits n and m, t times. I created ...
6
votes
2answers
170 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 ...
2
votes
1answer
40 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 ...
0
votes
3answers
130 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: ...
6
votes
1answer
123 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 ...
5
votes
1answer
8k views

16 bit checksum calculation [closed]

I need to calculate checksum using 16-bit ones' complement addition: ...
-3
votes
0answers
22 views

Receiving multiple inputs through a single scanf that are separated by spaces [closed]

I was assigned a project in which the input consists of 12 numbers that are separated by a space each. I thought that the following line of code would work ...
4
votes
2answers
35 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 ...
4
votes
2answers
47 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: ...
4
votes
2answers
52 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 ...
4
votes
0answers
43 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' ...
3
votes
4answers
93 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 ...
141
votes
17answers
26k views

Searching an element in a sorted array

I was applying for a position, and they asked me to complete a coding problem for them. I did so and submitted it, but I later found out I was rejected from the position. Anyways, I have an eclectic ...
3
votes
1answer
36 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 ...
8
votes
4answers
351 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". ...
6
votes
1answer
55 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 ...
10
votes
1answer
105 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 (...
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 ...
5
votes
0answers
49 views

Engineering an even faster qsort

I understand that C++ STL template sort runs faster than qsort in C because ...
4
votes
2answers
112 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 ...
8
votes
2answers
146 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: ...
2
votes
1answer
61 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: <...
0
votes
0answers
36 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. ...
3
votes
2answers
65 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 ...
5
votes
3answers
37k views

Trim function in C

I am trying to write an idiomatic trim function in C. How does this look? Should I instead malloc the new string and return it? ...
2
votes
1answer
41 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
28 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 ...
5
votes
2answers
3k views

Simple memory pool using no extra memory

I've borrowed the idea from the internet and I would like to know if my implementation is all right and what could be improved. It uses the free memory to store links to each node, so there's no ...
4
votes
1answer
37 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 ...
9
votes
2answers
1k views

C code to calculate the binary period of an integer

A non-empty zero-indexed string S consisting of Q characters is given. The period of this string is the smallest positive integer P such that: \$P ≤ Q/2\$ and \$S[K] = S[K+P]\$ for \$0 ≤ K &...
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 ...
1
vote
1answer
50 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 ...
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 ...
2
votes
2answers
64 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 ...
0
votes
0answers
40 views

What is an algorithm to solve sudoku in efficient way in c? [duplicate]

My sudoku solver works quite fast and quite good with small data (4*4 and 9*9 sudoku). But with 16*16 it takes too long and doesn't solve 25*25 sudoku at all. How can I improve my program in order to ...
13
votes
2answers
8k views

Read and write BMP file in C

I'm teaching myself a little C, and I've found this website. It has an exercise about manipulating a BMP file in C. I would like to know if I can make my code look more "idiomatic" or professional, ...
0
votes
2answers
18 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 ...
0
votes
1answer
53 views

Replace tabs in input and variable vs symbolic parameter [closed]

I am learning C and this is an exercise from The C Programmnig Languange by Brian and Ritchie. Write a program "detab" that replaces tabs in the input with the proper number of blanks to space to ...
1
vote
1answer
37 views

Function-based Tic-Tac-Toe game in C

This is a tic-tac-toe game that I made in C. It works the way that I want it to but I feel like I could have done it better or shorter. Any input as to how I did would be appreciated. Include ...