Stack Exchange Network

Stack Exchange network consists of 174 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
vote
0answers
8 views

C Generic Sorted Doubly-Linked List

I just finished this big project. Its is called SortedList and it is implemented using a Doubly-Linked List. It data is of type ...
0
votes
1answer
15 views

Automatically scan and resize buffer in C

I have a simple function that reads character by character from stdin, while resizing the buffer whenever needed. The implementation will only allow 256 characters to be read, but that can easily be ...
1
vote
0answers
18 views

K&R Exercise 1-22. Fold (break) lines at specified column

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 ...
1
vote
2answers
74 views

Doubly linked list in C

While I'm training to get better at C, I tried my hand at making a doubly linked list implementation. linkedlist.h ...
4
votes
2answers
42 views

Printing concentric squares of numbers

I wrote a code which prints the following pattern : ...
-4
votes
1answer
24 views

Two dice are randomly thrown 100 times [on hold]

Write a program to randomly throw the pair of dice 100 times, and to count:  How many times a total of “4” was scored  How many times “11” was scored  How many times a total less than 6 was ...
0
votes
1answer
42 views

Function to find and replace delimited blocks of string

I wanted to create a function which accepts a string & a delimiter. Finds the small blocks of string separated by the delimiters and replace the block based on some logic. I have created a simple ...
5
votes
1answer
75 views

K&R Exercise 1-21. Write a program `entab` that replaces strings of blanks with tabs

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 ...
5
votes
1answer
59 views

AVX512 - Add two 512-bit integers using _addcarryx_u64 function

My purpose is to add two __m512i variables (c = a + b) as efficiently as possible. To do so, I'd like to use the _addcarryx_u64 ...
-2
votes
0answers
21 views

A code to generate list of ordered pairs of numbers and find the maximum value of binary operations [closed]

I got a question at hackerrank which states that , a user should input a larger number (say 5) and a smaller number (say 4) . Then taking each pair from the oerdered list {1,2,3,4,5} , the binary and ...
-1
votes
0answers
28 views

Why do we index with 0 for arrays? (C) [closed]

So my question isn't really why do we index with zero but more so why does C allow arrays to break their own rules. Example: ...
-3
votes
0answers
13 views

Float type when inputed… Gives a different output [closed]

I am a beginner in programming and I was given an assignment.. I was asked to get 5 numbers of float type and print them in the reverse order of which I have given.. and this is my code... ...
11
votes
2answers
960 views

malloc() and free() for Linux with system calls

I have written an implementation of malloc() and free() for Linux using the sbrk() system ...
5
votes
1answer
76 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
74 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
61 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
52 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
48 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
61 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
173 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
81 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
68 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
74 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
89 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
29 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
74 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
69 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
87 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
50 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
45 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
122 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
71 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
44 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
210 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
110 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
75 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
37 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 ...
3
votes
1answer
45 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 <...
0
votes
1answer
63 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
106 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
224 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
66 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
70 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
50 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
98 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
113 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. ...