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.

0
votes
1answer
50 views

CMakeLists and Clang sanitization options for an ncurses program

I would like some feedback on a CMakeLists.txt file I created for compiling my project. I have pasted the CMakeLists as well as my source code below. One thing I would specifically appreciate feedback ...
4
votes
2answers
74 views

Converting fixed-width text file to CSV in C

I'm trying to get reacquainted with C after years of higher-level languages. I wrote a small fixed-width to CSV converter. It works (for ASCII at least) and it's quite fast, but I wonder if I missed ...
0
votes
1answer
52 views

Calculating the volume of a box

I've been studying more C using C Programming: A Modern Approach: A Modern Approach 2nd Edition by K.N. King as well as reading the comp.lang.c FAQ and the Code Review section here on Stack Exchange ...
5
votes
1answer
36 views

Mouse control of a camera in an OpenGL program

Introduction I'm doing an OpenGL program in C. As of now I'm working on the 3D camera system and got the control right. Now I'm working on the mouse control. It works, but I have used two different ...
2
votes
1answer
298 views

Simpletron in C without initial storing [closed]

I'm studying C with a Deitel's book. The book asks me to write a program that simulates a virtual PC (with virtual memory in an array called memory[100]). Then the ...
14
votes
3answers
1k views

Ncurses Tic Tac Toe with simplistic AI

I have read your rules and in particular the part about bite-sized portions, so I am apprehensive about posting this but want to do it anyway. I have recently begun getting into C and in particular ...
9
votes
3answers
2k views

A simple password manager in C

I wrote this simple program similar to "tiny password manager". Now I am looking for feedback how I can improve it. As always, a big topic in C code is error handling. So what programming techniques ...
6
votes
2answers
181 views

Extract specific positions from a char array

I have two arrays: char input[] = "ughIuytLikeretC"; and ...
3
votes
2answers
75 views

Project Euler #7: Nth prime number

I was solving Project Euler #7 on Hackerrank but for two cases, execution time is more than 2 sec. Can you help with optimizing? I'm new to programming. ...
2
votes
1answer
102 views

Simple Malloc Implementation

I've written an implementation of malloc, realloc, and free. I wanted to make a ...
1
vote
1answer
60 views

Quicksort in C with unit testing framework

This is my quicksort There are many like it but This quicksort is mine. So, quicksort, in C, with a big framework to test it six ways from Sunday. Passed the tests nicely, but there may be warts, or ...
1
vote
3answers
97 views

Functions to handle big numbers in C

I'm working to implement some simple bigint functions for addition, multiplication and powers. They work correctly but the larger the numbers the longer the time it takes. For example 2^10000 takes a ...
1
vote
2answers
44 views

“B1ff filter” reads and returns message

This is a programming exercise from chapter 8 of a C learning book by K N King. The program should prompt a user for a message, and return it after translating it to B1ff speak. e.g A->4, b->8 etc ...
2
votes
1answer
49 views

Block same instance of a program for running again

I am implementing a library (Linux) and I created some functions to block new instances of a running program and I was wonder if there are some better improvements for it. Here is a program which ...
2
votes
3answers
36 views

Command line test runner

This is a simple program to run a command-line program with given parameters and verify that it writes the expected output to stdout or stderr. The specification file is passed as the first argument. ...
1
vote
1answer
131 views

My function that combines strverscmp() with strcoll() [closed]

I'm writing a file manager which uses the ncurses-library in C. It aims to be a bit like the programs of the "suckless" community. To make it short, I needed to write my own comparison function for ...
2
votes
2answers
47 views

Platform-agnostic windowing library

I am making a C library that abstracts window creation with support for the new Vulkan API under a unified API; I have a github repository that you can check out. main.c ...
2
votes
2answers
138 views

My own algorithm to sort integers

I'm studying the C language with a Harvey Deitel book. Trying to solve an exercise that asked to write a good sorting algorithm, I did this: ...
2
votes
1answer
39 views

Extracting and reformatting dates from text

The task is find by pattern d--m--y---- all occurrences in text, reformat it to yyyy:mm:dd and print it separately from initial text. Actually I done all except formatting. And even in my written ...
1
vote
1answer
61 views

Generic Linked List (header-only and non-intrusive)

Although I should know better, I wrote my own linked list implementation in C. My goal was to make it a true generic collection, with no need to modify the structure being listed. I only ...
0
votes
2answers
53 views

Unbalanced Binary Search Tree insertion and search with random and sorted values

I have created this unbalanced binary search tree in C. Can anyone say this is a true approach or not? I have two scenarios for insertion and search: in the first scenario I am inserting 10000 random ...
4
votes
2answers
98 views

Conway's Game of Life in C (3 mode)

This is my program for the Game of life, I created it by myself with no reference or peer review so I need some comments and reviews on it. I created 3 modes: A. User Mode: The program asks the ...
2
votes
2answers
53 views

Parse IP address from a GPRS module reply

I'm writing a parser to get the IP address from a string I get from a GPRS module. Examples of the string I get from the GPRS module: +QIACT: 1,1,1,\"10.162.143.228\"\r\n\r\nOK\r\n +QIACT: 1,1,...
1
vote
2answers
68 views

Printing elements of an array in C

I'm trying to print the elements of an array in a fashion that resembles thism where SIZE is a constant: ...
5
votes
3answers
75 views

Closed linked-list which uses sentinels to avoid passing itself

This is a typical C implementation of a (doubly) linked-list. I want to avoid passing the element and the list itself to functions which operate on and possibly ...
1
vote
2answers
126 views

Quick & Simple Hash Table Implementation in C

First time implementing a hash table. I resolve collisions using the separate chaining method (closed addressing), i.e with linked lists. The hash function used is: ...
3
votes
2answers
85 views

Function to add two binary numbers in C

I tried to write a function bin_add() in C to add two positive binary numbers represented as zero terminated strings: ...
0
votes
2answers
63 views

Quick Sort c program

I recently learned quick sort through https://www.geeksforgeeks.org/quick-sort/ but found it hard to follow. So, from what I understand wrote the following program. ...
5
votes
3answers
95 views

Duel-type card game in C

This is similar to the game War, but with notable differences. For this program, it is the player versus the computer (so each with half of the deck). They draw the top card of their deck and compare....
6
votes
2answers
125 views

Calculate the cost of cement for a project

I am a newbie in a programming, and I just randomly chose a task for training from some group on Facebook. The task is to calculate the cost of cement for a construction project. The input is the ...
1
vote
3answers
63 views

Portably get one character from standard input using standard library only

While translating an old Basic game to C, I found myself needing a function to get one character from the keyboard. You can't do this with common standard C library functions like ...
2
votes
1answer
92 views

A* search on 4x4 sliding tile puzzle scales poorly

I am trying to improve the time complexity of my A* search algorithm and I have tried approaching this from every which way I believe is possible. I believe I may be doing something fundamentally ...
5
votes
1answer
68 views

JIT-based programming language

I'm working on JIT-based programming language using DynASM (before I was generating instructions directly). Review of the code would be really appreciated - It's my first time fiddling with DynASM. ...
7
votes
1answer
89 views

Red-black tree in C

I would like to verify that the code fulfills the specification of a red-black tree or receive suggestions for improvements. ...
1
vote
2answers
84 views

Calculating triangular numbers

A triangular number is a product of three factors as follows: $$ \text{Triangular number} = x(x + 1)(x + 2) $$ Is there a way to make this code faster? As it is the code calculates every triangular ...
3
votes
3answers
100 views

Parse a GET or POST string in C

This function takes a string from an HTTP POST or GET string, finds the specified variable, and allocates memory for the result and puts it in a string. The destination is given as an address of an ...
1
vote
0answers
30 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 ...
1
vote
2answers
77 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
1answer
49 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 ...
2
votes
2answers
139 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 ...
5
votes
2answers
155 views

Printing concentric squares of numbers

I wrote a code which prints the following pattern : ...
0
votes
1answer
47 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
119 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
87 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 ...
11
votes
2answers
1k 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
117 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
56 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? ...