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.

4
votes
0answers
47 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
45 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
55 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
48 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 ...
4
votes
2answers
86 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 ...
-1
votes
0answers
17 views

Simple C program which uses 'const' keyword generating an error [closed]

Why does the first two lines are generating an error but the last 3 lines in a different program works fine? ...
2
votes
1answer
58 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
61 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
72 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
88 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
87 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
545 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
157 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
46 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
26 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
795 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
94 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
123 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
41 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
23 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
53 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 ...
2
votes
1answer
294 views

Text-based Tic Tac Toe in C

I have programmed Tic Tac Toe in C. How can I improve the code? I have been told that system("cls") is not secure, but I don't know any other way of clearing the ...
0
votes
1answer
49 views

C - Argparse (Argument struct)

I'm trying to make something like Python's argparse in C. I created this Argument struct and functions; is my code good so far? ...
8
votes
3answers
2k views

Integers to English words in C

As a beginner in C programming, I decided to write a function words that, given an unsigned integer n, puts the English ...
2
votes
2answers
43 views

Find a palindromic string in C

This program tests whether a string is a palindrome or not. Can there be any improvements or shortcuts that can be used in the program. You can give any type of string as input. The program finds does ...
2
votes
2answers
61 views

NxN Sudoku Solver

I have written a Sudoku solver which can solve arbitrary NxN grids via backtracking. Since I'm relativly new to C any feedback is welcome. Code: ...
-2
votes
1answer
43 views

Deleting a node in Linked list [closed]

For deleting a node in linked list I used 3 steps: 1)Finding the previous node of the node to be deleted. 2)Changing the next of the previous node.(to know what is next see my code it's fully ...
4
votes
0answers
74 views

Command line todo list manager

This is a tiny project of mine, a minimal command line todo list program that I regularly use to manage my todos. It saves todos using GitHub markdown task lists format in a plain text file. The ...
5
votes
1answer
57 views

Plain C implementation of 'Cumulative All' operation for R

I want to implement a cumulative all through R's C interface. I was able to hack something together that produces the correct results, but I have little idea what idiomatic C should look like. The ...
4
votes
1answer
128 views

Huffman Coding library implemented in C

I have written a small library for C that implements the Huffman coding algorithm as outlined in David Huffman's paper on Minimum-Redundancy Codes, and a small test program to implement it. The ...
7
votes
7answers
178 views

Calculating frequency of a note from a string

I've been working on a solution to Pset3 of CS50 Harvard course for last couple of hours and managed to finish it. Although it works as intended I'm unhappy with how clean this code is, mostly because ...
3
votes
2answers
63 views

A Stack Implementation In C

I've written a very simple linked list based stack implementation and was wondering if this is the standard way to do it in C. ...
0
votes
1answer
27 views

read line endings sequentially

This is my first C program and I'm just looking for some constructive criticism before I start trying to do more with it. Am in quite unfamiliar territory here and am uncertain if I'm releasing all my ...
7
votes
2answers
644 views

Determining whether a provided credit card number is valid according to Luhn’s algorithm

I have been working on credit problem for edx CS50 and got it working as intended. an issue I find with it is the way I have to reinitialise the cardNumber variable ...
2
votes
1answer
63 views

Sysinfo parser for a window manager status bar

The program is written mainly for the status bar in dwm (a window manager for Linux), but it can be used for any manager that takes input from the root window in X. It queries different resources in ...
2
votes
1answer
52 views

Code Vita : Chakravyuha

Problem Statement A Chakravyuha is a wheel-like formation. Pictorially it is depicted as below A Chakravyuha has a very well-defined co-ordinate system. Each point on the co-...
2
votes
0answers
42 views

CUDA kernel to compare matrix entries, weighted with a pattern

I wonder if it's possible to optimize this code in CUDA. Could I get any hints how to? Equivalent algorithm runs faster in Matlab for me, but there I'm doing matrix operations. Compution I'm not ...
3
votes
0answers
46 views

Library for managing CLI flags

I'm pretty new to C, started learning it less than a month ago, the only language I had previous experience was Javascript. Anyways, I wrote a library for dealing with CLI flags. It's not a serious ...
4
votes
1answer
133 views

Generate Christmas Tree

Problem Statement: The Christmas tree is comprised of the following Parts Stand Each Part is further comprised of Branches. Branches are comprised of Leaves. How the tree appears as a ...
3
votes
3answers
178 views

Find k-distinct partitions which contain at least two perfect squares

Problem Statement: A k-distinct-partition of a number \$n\$ is a set of \$k\$ distinct positive integers that add up to \$n\$. For example, the 3-distinct partitions of 10 are \$1+2+7\$ \$...
3
votes
1answer
82 views

Function for scanning /proc

I wrote a function, scan_ps(), for scanning /proc, to replace a combination of popen() and <...
3
votes
3answers
108 views

Safely & portably read a value into a predefined integral type of varying size like mode_t

I need to read a value from a text file and put it into a predefined type, in this particular case mode_t. This typedef can have a variety of types underlying it, ...
-1
votes
2answers
67 views

Generating parentheses using DFS

I am solving the "Generating Parentheses Given a Number" challenge. The total number of parentheses combination turns out to be Catalan Series. The following code works but I am looking for comment on ...
1
vote
2answers
38 views

Exercise 6.1 from ANSI C book - getword function

I have a following exercise from ANSI C book: Exercise 6.1. Our version of getword does not properly handle underscores, string constants, comments, or preprocessor control lines. Write a ...
0
votes
2answers
49 views

Function to copy a file using sendfile

I've just found out there is sendfile(). In the man page of sendfile(), it says: ...
1
vote
2answers
66 views

K&R Exercise 5-15: sorting with extra options

As I'm learning to program in C, I'm making my way through K&R. The goal of the exercise is to add a option to the program so that the sorting does not depend on upper or lower-case letters. ...
2
votes
2answers
68 views

Random binary digit generation and file I/O

I've recently made a program which generates a (pseudo) random binary digit (1,0) which is tied to a specific subject to learn for every day of the week. The program generates the digits the first ...
3
votes
1answer
46 views

Counting sort in C, revised

This is a revised follow-up to this question. I have implemented most of the suggestions in the accepted answer. I am interested to see what I could improve in my code and what I could do to make it ...
3
votes
2answers
70 views

Counting sort in C

EDIT: I have posted a follow-up to this question. I have implemented counting sort in C. This program takes its input as integers from command line arguments, sorts the integers with counting sort, ...
3
votes
1answer
72 views

Convert string to double and check for errors

The following program converts a string to a double, and checks for errors. It uses the strtod() function to do the conversion, and follows the example given for ...