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.

5
votes
1answer
122 views

K&R Exercise 1-18. Remove trailing blanks and tabs from each line

Intro I'm going through the K&R book (2nd edition, ANSI C ver.) and want to get the most from it: learn (outdated) C and practice problem-solving at the same time. I believe that the author's ...
4
votes
2answers
107 views

C bit mask calculator written using GTK+ 3

I've been studying C on my own using K&R 2nd Edition, and started exploring GTK+ to practice some of the concepts I've learned by making GUI applications. This is the first GUI application I've ...
1
vote
2answers
77 views

Merge Sort code in C

Below is the code of Merge Sort for sorting an integer array in ascending order of values written by me. By looking at the code, I am thinking I can make the code more compact and secure, but not ...
0
votes
2answers
56 views

Finding primes from random integers

I was hoping I could get some help making my code more efficient. I'm a math major taking an Intro to Programming class, and I was asked to write a C program that generates: A text file named ...
3
votes
1answer
57 views

htmlspecialchars() equivalent in C

I'm trying to write an equivalent of PHP's htmlspecialchars() in C. What is my implementation missing or doing wrong? ...
0
votes
1answer
298 views

Minimum number of swaps required to sort the array in ascending order

Here is my problem statement. An excerpt: You are given an unordered array consisting of consecutive integers ∈ [1, 2, 3, ..., n] without any duplicates. You are ...
6
votes
4answers
191 views

Efficiently swapping the first and last five bits in an unsigned 16-bit integer in C

I'm programming on an 8-bit Z80 embedded system, and encountered a problem. The program needs to render some pixels to the screen. The color is stored as RGB565 format as a 16-bit unsigned integer, ...
2
votes
4answers
88 views

K&R Exercise 1-19. Reverse program input one line at a time

Intro I'm going through the K&R book (2nd edition, ANSI C ver.) and want to get the most from it: learn (outdated) C and practice problem-solving at the same time. For that reason, I'm trying to ...
4
votes
3answers
1k views

Extracting a specific substring in C

I have a string like this: char buffer[] = "blablabla$GPTXT->SOME CODES HERE<-\r\n$GPRMCblablabla"; It is sent from an external device and changes every 1 ...
1
vote
2answers
107 views

K&R Exercise 1-16. Find the longest line in the input and print its length and first N characters

I'm going through the K&R book (2nd edition, ANSI C ver.) and want to get the most from it. Note that, for the sake of exercise, I don't want to use techniques not introduced yet in the book and I'...
2
votes
1answer
102 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 ...
3
votes
0answers
118 views

K&R Exercise 1-13. Printing histogram of word lengths (vertical variant)

I'm going through the K&R book (2nd edition, ANSI C ver.) and want to get the most from it. How does the following solution look to you? Note that, for the sake of exercise, I don't want to use ...
2
votes
0answers
30 views

Trying to create a directory if it doesn't exist [closed]

I am trying to create a directory, but I have to check whether /usr is present initially, later /usr/local is present and so on, ...
3
votes
2answers
89 views

K&R Exercise 1-13. Printing histogram of word lengths (horizontal variant)

I'm going through the K&R book (2nd edition, ANSI C ver.) and want to get the most from it. How does the following solution look to you? Note that, for the sake of exercise, I don't want to use ...
1
vote
3answers
75 views

Find the cheapest order placed out of all of the stores visited - follow-up #3

Made some adjustments to the previous code thanks to the helpful and thoughtful review by @SergeBallesta, @TobySpeight, @G.Sliepen, and @Edward. Problem statement: This program should ask for the ...
1
vote
1answer
102 views

Pong Ultimate - Pong with 4 paddles

This is a pong game with 4 paddles. The paddles are always on the same height as the mouse. I wrote it in C using SDL. The Makefile works for linux. Do you think the code is readable or should I ...
4
votes
1answer
79 views

Implementing a queue using a linked-list

In my intro CS class we're reviewing data structures. I'm currently working on implementing a queue using a linked list (FIFO) in C. I'd appreciate a review of the implementation as well as of my ...
-2
votes
1answer
54 views

Remove key-value pairs from string when only key is given

I have a need to parse strings that contain pairs of key : value, and remove a specific pair, when I'm only given the key. Example: Given the string ...
24
votes
6answers
5k views

Create a C style char** from a C++ vector<string>

I am dealing with some older C style APIs, like Posix execve that take a char**. In the rest of my code, I prefer to use a ...
3
votes
6answers
131 views

Length of the integer part of a double in C without math.h

I came up with this simple function to return the length of a double, working fine in all my test but want to make sure that this code will work in all doubles, can't think of a case in which it would ...
2
votes
3answers
122 views

Implementing a stack using a linked-list

In my intro CS class we're reviewing data structures. I'm currently working on implementing a stack using a linked list (LIFO) in C. I'd appreciate a review of the implementation as well as of my ...
1
vote
1answer
48 views

Find the cheapest order placed out of all of the stores visited - follow-up #2

Made some adjustments to the previous code thanks to the helpful and thoughtful review by @G.Sliepen. Problem statement: This program should ask for the total number of shops that will be ...
0
votes
2answers
218 views

Find the cheapest order placed out of all of the stores visited - follow-up #1

Made some adjustments to my original program. Here's a link to it: original. Also, here's a link to the problem statement: problem statement. The assignment is past due; The code I turned in is ...
1
vote
3answers
118 views

Convert integer to decimal string

I have a need to do some conversions in a loop to display the results using C++98 on Linux, which doesn't have any itoa() to complement ...
1
vote
1answer
85 views

Find the cheapest order placed out of all of the stores visited

@Serge Bellesta suggested that once my program works correctly, I should consider posting it in Code Review to get interesting comments on it. Problem statement(pdf): I would like my code to be more ...
2
votes
1answer
40 views

Dockerfile + CI for C build

I recently built a CI for my course project in C. I made 3 stages, to build docker image, compile my C sources and run the said project. That said, i think i could've do way better here but i don't ...
4
votes
1answer
53 views

Hungarian algorithm to perform least-cost assignments

The Hungarian algorithm solves the assignment problem, and I'm looking for any suggestions regarding improvement on my implementation (also coding style). It is based on the wikipedia entry and ...
9
votes
4answers
2k views

Comparing two large binary files in C

I'm trying to read two sufficiently large binary files, comparing them and printing the offset at which they differ. I'm using fread to read the binary files and <...
-1
votes
1answer
69 views

gcc constant time implemenation [closed]

I need to make the following function time constant - I have already removed if statements and have written it down to one line in the loop. ...
7
votes
2answers
202 views

Fixed-sized memory pool in C

I'm learning C and I am currently implementing a memory pool. I'm writing it in steps, first I implemented a fixed-sized memory pool then I will try to implement a memory pool with a known size of ...
8
votes
1answer
355 views

Gameboy emulator in C

I've been coding a Gameboy emulator in C for some time(seems like a common project for people). It's reasonably functional and has some MBC1 support, but has some minor graphical glitches still. I'...
2
votes
3answers
70 views

Stacks using Linked Lists in C

I tried to implement a stack using Linked Lists. How could I make it more efficient? Any other suggestions will be greatly appreciated. I am a beginner C programmer. Any other tips to clean up my ...
0
votes
1answer
78 views

Hash function in C for sets and associative arrays

I wrote a non-cryptographic hash function in C, which I am hoping might be suitable for use in an implementation of hash sets or hash maps. ...
-4
votes
1answer
51 views

Embedded code for another executable - Lara walk handler decompilation [closed]

I'm writing an independent code which I'll import into an exe, Here is an self-contained example: This code is a PCSTATE handler - basically when lara starts walking - this code will be executed. It ...
5
votes
2answers
112 views

Object pool and sorted linked list in C

Update: Have implemented some of the suggestions: See GitHub: https://github.com/BostonBrooks/MathsGame/tree/master/Object_Pools_Demo I am implementing a game engine where I have a sorted list of ...
2
votes
1answer
219 views

MiniMax Algorithm

This is my C implementation of the Minimax Algorithm to play tic-tac-toe. I consider myself a C beginner so any feedback on style, best practices, or efficiency is more than welcome. ...
3
votes
2answers
327 views

Brute force passwords in C (CS50 exercise)

This script attempts to crack passwords by going through all possible 'words', hashing them, and comparing the hash to the input. It seems to work, but I don't know if I have written 'good' C. I'm ...
6
votes
4answers
88 views

Label my cassette boxes

Historical Friday: this was my first useful C program, written around 1993-1994 (with only occasional access to a compiler and runtime environment). It's also my first non-trivial Postscript, too. ...
2
votes
1answer
102 views

Deadbeef : finding all words made of hexadecimal digits

Hexadecimal 0xdead, 0xbeef are the magic numbers because they're also English words. I decided to find such words as many as possible. How to do it? We need large ...
3
votes
1answer
122 views

Optimizations of C Code - Bilateral Filter

I'm working on a nice approximation for the Bilateral Filter. I have a working code which runs pretty fast yet still I think much can be improved. The code (C Code,...
9
votes
2answers
656 views

Generating the powerset in C

I am solving another problem in leetcode. Given a set, generate all the subsets of the set. Input: [1,2,3] Output: ...
5
votes
2answers
172 views

Deficient Numbers

I have found the following interesting challenge on the web: Deficient Numbers A number is considered deficient if the sum of its factors is less than twice that number. For example: 10 is a ...
2
votes
1answer
71 views

Split a string based on a delimiter in C

Basically, this code splits a string into substrings based on a token. The printf call is just a placeholder for something useful for each substring and can be ...
0
votes
1answer
29 views

Handler for default values in a CLI flag utility library in C

I am developing a very basic CLI flag utility library in C. The following code is a part of the main translation unit containing all the relevant functions, and is located in the global scope. ...
6
votes
5answers
912 views

Dynamic fgets in C

I wanted to make a function that will dynamically retrieve a line from a stream to a buffer. This function just needs to take in the char* and the stream to read ...
2
votes
1answer
116 views

Printing 64-bit decimal numbers in freestanding environment

I need to print signed 64-bit numbers in decimal form. Program runs in freestanding environment (no C library available, libgcc may be unavailable too, or may not work correctly). So I can't use ...
4
votes
0answers
134 views

Fast Hardy-Weinberg equilibrium simulation

I was very bored over one of my breaks this year, so I built a Hardy-Weinberg equilibrium simulator for two unrelated alleles of the same gene. Hardy-Weinberg equilibrium is when there is no evolution,...
1
vote
2answers
44 views

Running shell script as root via external binary

I'm not an experienced Linux user and I wanted an easy way to run shell scripts as root from a PHP script, I came up with this: ...
2
votes
0answers
32 views

Getting an element from RCU-protected list in kernel

I wrote a function, read_fox_rcu() for getting an element from RCU-protected list in a linux device driver. read_fox_rcu() reads ...
1
vote
0answers
58 views

selecting 5 best players out of 2 team

Let us assume that we need to develop an application which can select best 11 players to score maximum points. The application will select the best players after completion of a match. The rules are ...